hass-core/homeassistant/components/myuplink/helpers.py
Åke Strandberg c167001861
Add myuplink switch platform (#110810)
* Add switch platform

* Add mypulink switch platform

* Update tests according to review

* Address more review comments

* Adjust types

* More typing

* Fix typo

* Use constants in tests

* Revert constants

* Catch aiohttp.ClientError when API call fails

* Add test case for failed async_set_device_points call

* Test api failures for both toggle directions

* Use parametrize for testing switching
2024-02-22 11:27:46 +01:00

19 lines
539 B
Python

"""Helper collection for myuplink."""
from myuplink import DevicePoint
from homeassistant.const import Platform
def find_matching_platform(device_point: DevicePoint) -> Platform:
"""Find entity platform for a DevicePoint."""
if (
len(device_point.enum_values) == 2
and device_point.enum_values[0]["value"] == "0"
and device_point.enum_values[1]["value"] == "1"
):
if device_point.writable:
return Platform.SWITCH
return Platform.BINARY_SENSOR
return Platform.SENSOR