1 """Support for VersaSense actuator peripheral."""
3 from __future__
import annotations
25 _LOGGER = logging.getLogger(__name__)
31 async_add_entities: AddEntitiesCallback,
32 discovery_info: DiscoveryInfoType |
None =
None,
34 """Set up actuator platform."""
35 if discovery_info
is None:
38 consumer = hass.data[DOMAIN][KEY_CONSUMER]
42 for entity_info
in discovery_info.values():
43 peripheral = hass.data[DOMAIN][entity_info[KEY_PARENT_MAC]][
44 entity_info[KEY_IDENTIFIER]
46 parent_name = entity_info[KEY_PARENT_NAME]
47 unit = entity_info[KEY_UNIT]
48 measurement = entity_info[KEY_MEASUREMENT]
51 VActuator(peripheral, parent_name, unit, measurement, consumer)
58 """Representation of an Actuator."""
60 def __init__(self, peripheral, parent_name, unit, measurement, consumer):
61 """Initialize the sensor."""
64 self.
_name_name = f
"{parent_name} {measurement}"
73 """Return the unique id of the actuator."""
74 return f
"{self._parent_mac}/{self._identifier}/{self._measurement}"
78 """Return the name of the actuator."""
79 return self.
_name_name
83 """Return the state of the actuator."""
88 """Return if the actuator is available."""
92 """Turn off the actuator."""
96 """Turn on the actuator."""
100 """Update the state of the actuator."""
101 payload = {
"id":
"state-num",
"value": state}
103 await self.
consumerconsumer.actuatePeripheral(
108 """Fetch state data from the actuator."""
109 samples = await self.
consumerconsumer.fetchPeripheralSample(
113 if samples
is not None:
114 for sample
in samples:
117 if sample.value == PERIPHERAL_STATE_OFF:
119 elif sample.value == PERIPHERAL_STATE_ON:
123 _LOGGER.error(
"Sample unavailable")
def __init__(self, peripheral, parent_name, unit, measurement, consumer)
None async_turn_on(self, **Any kwargs)
def update_state(self, state)
None async_turn_off(self, **Any kwargs)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)