* 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
19 lines
539 B
Python
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
|