1 """Support for interacting with Smappee Comport Plugs, Switches and Output Modules."""
10 from .
import SmappeeConfigEntry
11 from .const
import DOMAIN
13 SWITCH_PREFIX =
"Switch"
18 config_entry: SmappeeConfigEntry,
19 async_add_entities: AddEntitiesCallback,
21 """Set up the Smappee Comfort Plugs."""
22 smappee_base = config_entry.runtime_data
25 for service_location
in smappee_base.smappee.service_locations.values():
26 for actuator_id, actuator
in service_location.actuators.items():
27 if actuator.type
in (
"SWITCH",
"COMFORT_PLUG"):
35 actuator.serialnumber,
38 elif actuator.type ==
"INFINITY_OUTPUT_MODULE":
46 actuator.serialnumber,
47 actuator_state_option=option,
49 for option
in actuator.state_options
56 """Representation of a Smappee Comport Plug."""
58 _attr_icon =
"mdi:toggle-switch"
67 actuator_serialnumber,
68 actuator_state_option=None,
70 """Initialize a new Smappee Comfort Plug."""
78 self.
_state_state = service_location.actuators.get(actuator_id).state
83 identifiers={(DOMAIN, service_location.device_serial_number)},
84 manufacturer=
"Smappee",
85 model=service_location.device_model,
86 name=service_location.service_location_name,
87 sw_version=service_location.firmware_version,
92 """Return the name of the switch."""
95 f
"{self._service_location.service_location_name} - "
96 f
"Output module - {self._actuator_name} - {self._actuator_state_option}"
101 f
"{self._service_location.service_location_name} - "
102 f
"{self._actuator_type.title()} - {self._actuator_name}"
107 """Return true if switch is on."""
115 return self.
_state_state ==
"ON_ON"
118 """Turn on Comport Plug."""
119 if self.
_actuator_type_actuator_type
in (
"SWITCH",
"COMFORT_PLUG"):
121 elif self.
_actuator_type_actuator_type ==
"INFINITY_OUTPUT_MODULE":
127 """Turn off Comport Plug."""
128 if self.
_actuator_type_actuator_type
in (
"SWITCH",
"COMFORT_PLUG"):
132 elif self.
_actuator_type_actuator_type ==
"INFINITY_OUTPUT_MODULE":
134 self.
_actuator_id_actuator_id, state=
"PLACEHOLDER", api=
False
139 """Return True if entity is available. Unavailable for COMFORT_PLUGS."""
149 """Return the unique ID for this switch."""
152 f
"{self._service_location.device_serial_number}-"
153 f
"{self._service_location.service_location_id}-actuator-"
154 f
"{self._actuator_id}-{self._actuator_state_option}"
159 f
"{self._service_location.device_serial_number}-"
160 f
"{self._service_location.service_location_id}-actuator-"
161 f
"{self._actuator_id}"
165 """Get the latest data from Smappee and update the state."""
169 if new_state != self.
_state_state:
170 self.
_state_state = new_state
def __init__(self, smappee_base, service_location, name, actuator_id, actuator_type, actuator_serialnumber, actuator_state_option=None)
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, SmappeeConfigEntry config_entry, AddEntitiesCallback async_add_entities)