mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add entity translations to Rachio (#98917)
This commit is contained in:
parent
c47983621c
commit
577f545113
@ -43,7 +43,6 @@ async def async_setup_entry(
|
|||||||
"""Set up the Rachio binary sensors."""
|
"""Set up the Rachio binary sensors."""
|
||||||
entities = await hass.async_add_executor_job(_create_entities, hass, config_entry)
|
entities = await hass.async_add_executor_job(_create_entities, hass, config_entry)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
_LOGGER.debug("%d Rachio binary sensor(s) added", len(entities))
|
|
||||||
|
|
||||||
|
|
||||||
def _create_entities(hass: HomeAssistant, config_entry: ConfigEntry) -> list[Entity]:
|
def _create_entities(hass: HomeAssistant, config_entry: ConfigEntry) -> list[Entity]:
|
||||||
@ -58,6 +57,8 @@ def _create_entities(hass: HomeAssistant, config_entry: ConfigEntry) -> list[Ent
|
|||||||
class RachioControllerBinarySensor(RachioDevice, BinarySensorEntity):
|
class RachioControllerBinarySensor(RachioDevice, BinarySensorEntity):
|
||||||
"""Represent a binary sensor that reflects a Rachio state."""
|
"""Represent a binary sensor that reflects a Rachio state."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, controller):
|
def __init__(self, controller):
|
||||||
"""Set up a new Rachio controller binary sensor."""
|
"""Set up a new Rachio controller binary sensor."""
|
||||||
super().__init__(controller)
|
super().__init__(controller)
|
||||||
@ -86,26 +87,13 @@ class RachioControllerBinarySensor(RachioDevice, BinarySensorEntity):
|
|||||||
class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
|
class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
|
||||||
"""Represent a binary sensor that reflects if the controller is online."""
|
"""Represent a binary sensor that reflects if the controller is online."""
|
||||||
|
|
||||||
@property
|
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of this sensor including the controller name."""
|
|
||||||
return self._controller.name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique id for this entity."""
|
"""Return a unique id for this entity."""
|
||||||
return f"{self._controller.controller_id}-online"
|
return f"{self._controller.controller_id}-online"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> BinarySensorDeviceClass:
|
|
||||||
"""Return the class of this device, from BinarySensorDeviceClass."""
|
|
||||||
return BinarySensorDeviceClass.CONNECTIVITY
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return the name of an icon for this sensor."""
|
|
||||||
return "mdi:wifi-strength-4" if self.is_on else "mdi:wifi-strength-off-outline"
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_update(self, *args, **kwargs) -> None:
|
def _async_handle_update(self, *args, **kwargs) -> None:
|
||||||
"""Handle an update to the state of this sensor."""
|
"""Handle an update to the state of this sensor."""
|
||||||
@ -132,26 +120,14 @@ class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
|
|||||||
class RachioRainSensor(RachioControllerBinarySensor):
|
class RachioRainSensor(RachioControllerBinarySensor):
|
||||||
"""Represent a binary sensor that reflects the status of the rain sensor."""
|
"""Represent a binary sensor that reflects the status of the rain sensor."""
|
||||||
|
|
||||||
@property
|
_attr_device_class = BinarySensorDeviceClass.MOISTURE
|
||||||
def name(self) -> str:
|
_attr_translation_key = "rain"
|
||||||
"""Return the name of this sensor including the controller name."""
|
|
||||||
return f"{self._controller.name} rain sensor"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique id for this entity."""
|
"""Return a unique id for this entity."""
|
||||||
return f"{self._controller.controller_id}-rain_sensor"
|
return f"{self._controller.controller_id}-rain_sensor"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> BinarySensorDeviceClass:
|
|
||||||
"""Return the class of this device."""
|
|
||||||
return BinarySensorDeviceClass.MOISTURE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return the icon for this sensor."""
|
|
||||||
return "mdi:water" if self.is_on else "mdi:water-off"
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_update(self, *args, **kwargs) -> None:
|
def _async_handle_update(self, *args, **kwargs) -> None:
|
||||||
"""Handle an update to the state of this sensor."""
|
"""Handle an update to the state of this sensor."""
|
||||||
|
@ -27,6 +27,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"rain": {
|
||||||
|
"name": "Rain"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"standby": {
|
||||||
|
"name": "Standby"
|
||||||
|
},
|
||||||
|
"rain_delay": {
|
||||||
|
"name": "Rain delay"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"set_zone_moisture_percent": {
|
"set_zone_moisture_percent": {
|
||||||
"name": "Set zone moisture percent",
|
"name": "Set zone moisture percent",
|
||||||
|
@ -109,7 +109,6 @@ async def async_setup_entry(
|
|||||||
has_flex_sched = True
|
has_flex_sched = True
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
_LOGGER.debug("%d Rachio switch(es) added", len(entities))
|
|
||||||
|
|
||||||
def start_multiple(service: ServiceCall) -> None:
|
def start_multiple(service: ServiceCall) -> None:
|
||||||
"""Service to start multiple zones in sequence."""
|
"""Service to start multiple zones in sequence."""
|
||||||
@ -173,7 +172,6 @@ def _create_entities(hass: HomeAssistant, config_entry: ConfigEntry) -> list[Ent
|
|||||||
entities.append(RachioZone(person, controller, zone, current_schedule))
|
entities.append(RachioZone(person, controller, zone, current_schedule))
|
||||||
for sched in schedules + flex_schedules:
|
for sched in schedules + flex_schedules:
|
||||||
entities.append(RachioSchedule(person, controller, sched, current_schedule))
|
entities.append(RachioSchedule(person, controller, sched, current_schedule))
|
||||||
_LOGGER.debug("Added %s", entities)
|
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
||||||
@ -185,11 +183,6 @@ class RachioSwitch(RachioDevice, SwitchEntity):
|
|||||||
super().__init__(controller)
|
super().__init__(controller)
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Get a name for this switch."""
|
|
||||||
return f"Switch on {self._controller.name}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return whether the switch is currently on."""
|
"""Return whether the switch is currently on."""
|
||||||
@ -213,21 +206,15 @@ class RachioSwitch(RachioDevice, SwitchEntity):
|
|||||||
class RachioStandbySwitch(RachioSwitch):
|
class RachioStandbySwitch(RachioSwitch):
|
||||||
"""Representation of a standby status/button."""
|
"""Representation of a standby status/button."""
|
||||||
|
|
||||||
@property
|
_attr_has_entity_name = True
|
||||||
def name(self) -> str:
|
_attr_translation_key = "standby"
|
||||||
"""Return the name of the standby switch."""
|
_attr_icon = "mdi:power"
|
||||||
return f"{self._controller.name} in standby mode"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique id by combining controller id and purpose."""
|
"""Return a unique id by combining controller id and purpose."""
|
||||||
return f"{self._controller.controller_id}-standby"
|
return f"{self._controller.controller_id}-standby"
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return an icon for the standby switch."""
|
|
||||||
return "mdi:power"
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_update(self, *args, **kwargs) -> None:
|
def _async_handle_update(self, *args, **kwargs) -> None:
|
||||||
"""Update the state using webhook data."""
|
"""Update the state using webhook data."""
|
||||||
@ -263,26 +250,20 @@ class RachioStandbySwitch(RachioSwitch):
|
|||||||
class RachioRainDelay(RachioSwitch):
|
class RachioRainDelay(RachioSwitch):
|
||||||
"""Representation of a rain delay status/switch."""
|
"""Representation of a rain delay status/switch."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_translation_key = "rain_delay"
|
||||||
|
_attr_icon = "mdi:camera-timer"
|
||||||
|
|
||||||
def __init__(self, controller):
|
def __init__(self, controller):
|
||||||
"""Set up a Rachio rain delay switch."""
|
"""Set up a Rachio rain delay switch."""
|
||||||
self._cancel_update = None
|
self._cancel_update = None
|
||||||
super().__init__(controller)
|
super().__init__(controller)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the switch."""
|
|
||||||
return f"{self._controller.name} rain delay"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique id by combining controller id and purpose."""
|
"""Return a unique id by combining controller id and purpose."""
|
||||||
return f"{self._controller.controller_id}-delay"
|
return f"{self._controller.controller_id}-delay"
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return an icon for rain delay."""
|
|
||||||
return "mdi:camera-timer"
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_update(self, *args, **kwargs) -> None:
|
def _async_handle_update(self, *args, **kwargs) -> None:
|
||||||
"""Update the state using webhook data."""
|
"""Update the state using webhook data."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user