1 """Support for ANEL PwrCtrl switches."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from anel_pwrctrl
import Device, DeviceMaster, Switch
10 import voluptuous
as vol
13 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
23 _LOGGER = logging.getLogger(__name__)
25 CONF_PORT_RECV =
"port_recv"
26 CONF_PORT_SEND =
"port_send"
30 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
32 vol.Required(CONF_PORT_RECV): cv.port,
33 vol.Required(CONF_PORT_SEND): cv.port,
34 vol.Required(CONF_USERNAME): cv.string,
35 vol.Required(CONF_PASSWORD): cv.string,
36 vol.Optional(CONF_HOST): cv.string,
44 add_entities: AddEntitiesCallback,
45 discovery_info: DiscoveryInfoType |
None =
None,
47 """Set up PwrCtrl devices/switches."""
48 host = config.get(CONF_HOST)
49 username = config[CONF_USERNAME]
50 password = config[CONF_PASSWORD]
51 port_recv = config[CONF_PORT_RECV]
52 port_send = config[CONF_PORT_SEND]
55 master = DeviceMaster(
61 master.query(ip_addr=host)
63 _LOGGER.error(
"Unable to discover PwrCtrl device: %s",
str(ex))
66 devices: list[SwitchEntity] = []
67 for device
in master.devices.values():
70 PwrCtrlSwitch(switch, parent_device)
for switch
in device.switches.values()
77 """Representation of a PwrCtrl switch."""
79 def __init__(self, port: Switch, parent_device: PwrCtrlDevice) ->
None:
80 """Initialize the PwrCtrl switch."""
87 """Trigger update for all switches on the parent device."""
92 """Turn the switch on."""
96 """Turn the switch off."""
101 """Device representation for per device throttling."""
104 """Initialize the PwrCtrl device."""
107 @Throttle(MIN_TIME_BETWEEN_UPDATES)
109 """Update the device and all its switches."""
None __init__(self, Device device)
None __init__(self, Switch port, PwrCtrlDevice parent_device)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
str|float get_state(dict[str, float] data, str key)