1 """Elmax switch platform."""
7 from elmax_api.model.command
import SwitchCommand
8 from elmax_api.model.panel
import PanelStatus
15 from .const
import DOMAIN
16 from .coordinator
import ElmaxCoordinator
17 from .entity
import ElmaxEntity
19 _LOGGER = logging.getLogger(__name__)
24 config_entry: ConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up the Elmax switch platform."""
28 coordinator: ElmaxCoordinator = hass.data[DOMAIN][config_entry.entry_id]
31 def _discover_new_devices():
32 panel_status: PanelStatus = coordinator.data
34 if panel_status
is None:
39 for actuator
in panel_status.actuators:
41 if actuator.endpoint_id
in known_devices:
44 elmax_device=actuator,
45 panel_version=panel_status.release,
46 coordinator=coordinator,
48 entities.append(entity)
52 known_devices.update([entity.unique_id
for entity
in entities])
55 remove_handle = coordinator.async_add_listener(_discover_new_devices)
56 config_entry.async_on_unload(remove_handle)
59 _discover_new_devices()
63 """Implement the Elmax switch entity."""
67 """Return True if entity is on."""
71 """Refresh data and wait until the state changes."""
75 await asyncio.sleep(2.0)
80 if new_state == old_state:
82 await asyncio.sleep(5.0)
88 return new_state != old_state
91 """Turn the entity on."""
92 await self.coordinator.http_client.execute_command(
93 endpoint_id=self.
_device_device.endpoint_id, command=SwitchCommand.TURN_ON
99 """Turn the entity off."""
100 await self.coordinator.http_client.execute_command(
101 endpoint_id=self.
_device_device.endpoint_id, command=SwitchCommand.TURN_OFF
Actuator get_actuator_state(self, str actuator_id)
None async_turn_off(self, **Any kwargs)
bool _wait_for_state_change(self)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)