1 """The power switch which can be toggled via the APsystems local API integration."""
3 from __future__
import annotations
7 from aiohttp.client_exceptions
import ClientConnectionError
8 from APsystemsEZ1
import InverterReturnedError
14 from .
import ApSystemsConfigEntry, ApSystemsData
15 from .entity
import ApSystemsEntity
20 config_entry: ApSystemsConfigEntry,
21 add_entities: AddEntitiesCallback,
23 """Set up the switch platform."""
29 """The switch class for APSystems switches."""
31 _attr_device_class = SwitchDeviceClass.SWITCH
32 _attr_translation_key =
"inverter_status"
34 def __init__(self, data: ApSystemsData) ->
None:
35 """Initialize the switch."""
37 self.
_api_api = data.coordinator.api
41 """Update switch status and availability."""
43 status = await self.
_api_api.get_device_power_status()
44 except (TimeoutError, ClientConnectionError, InverterReturnedError):
51 """Turn the switch on."""
52 await self.
_api_api.set_device_power_status(
True)
55 """Turn the switch off."""
56 await self.
_api_api.set_device_power_status(
False)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, ApSystemsData data)
None async_setup_entry(HomeAssistant hass, ApSystemsConfigEntry config_entry, AddEntitiesCallback add_entities)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)