From 577f545113659f77b5d96d942e1c04ec87512b2a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 24 Aug 2023 11:43:10 +0200 Subject: [PATCH] Add entity translations to Rachio (#98917) --- .../components/rachio/binary_sensor.py | 34 +++---------------- homeassistant/components/rachio/strings.json | 15 ++++++++ homeassistant/components/rachio/switch.py | 33 ++++-------------- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/homeassistant/components/rachio/binary_sensor.py b/homeassistant/components/rachio/binary_sensor.py index f1c515d37f7..029b1bac6e3 100644 --- a/homeassistant/components/rachio/binary_sensor.py +++ b/homeassistant/components/rachio/binary_sensor.py @@ -43,7 +43,6 @@ async def async_setup_entry( """Set up the Rachio binary sensors.""" entities = await hass.async_add_executor_job(_create_entities, hass, config_entry) async_add_entities(entities) - _LOGGER.debug("%d Rachio binary sensor(s) added", len(entities)) 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): """Represent a binary sensor that reflects a Rachio state.""" + _attr_has_entity_name = True + def __init__(self, controller): """Set up a new Rachio controller binary sensor.""" super().__init__(controller) @@ -86,26 +87,13 @@ class RachioControllerBinarySensor(RachioDevice, BinarySensorEntity): class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor): """Represent a binary sensor that reflects if the controller is online.""" - @property - def name(self) -> str: - """Return the name of this sensor including the controller name.""" - return self._controller.name + _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY @property def unique_id(self) -> str: """Return a unique id for this entity.""" 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 def _async_handle_update(self, *args, **kwargs) -> None: """Handle an update to the state of this sensor.""" @@ -132,26 +120,14 @@ class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor): class RachioRainSensor(RachioControllerBinarySensor): """Represent a binary sensor that reflects the status of the rain sensor.""" - @property - def name(self) -> str: - """Return the name of this sensor including the controller name.""" - return f"{self._controller.name} rain sensor" + _attr_device_class = BinarySensorDeviceClass.MOISTURE + _attr_translation_key = "rain" @property def unique_id(self) -> str: """Return a unique id for this entity.""" 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 def _async_handle_update(self, *args, **kwargs) -> None: """Handle an update to the state of this sensor.""" diff --git a/homeassistant/components/rachio/strings.json b/homeassistant/components/rachio/strings.json index 2132cab8682..560c300db17 100644 --- a/homeassistant/components/rachio/strings.json +++ b/homeassistant/components/rachio/strings.json @@ -27,6 +27,21 @@ } } }, + "entity": { + "binary_sensor": { + "rain": { + "name": "Rain" + } + }, + "switch": { + "standby": { + "name": "Standby" + }, + "rain_delay": { + "name": "Rain delay" + } + } + }, "services": { "set_zone_moisture_percent": { "name": "Set zone moisture percent", diff --git a/homeassistant/components/rachio/switch.py b/homeassistant/components/rachio/switch.py index c04a1a09f81..0557a2bdb19 100644 --- a/homeassistant/components/rachio/switch.py +++ b/homeassistant/components/rachio/switch.py @@ -109,7 +109,6 @@ async def async_setup_entry( has_flex_sched = True async_add_entities(entities) - _LOGGER.debug("%d Rachio switch(es) added", len(entities)) def start_multiple(service: ServiceCall) -> None: """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)) for sched in schedules + flex_schedules: entities.append(RachioSchedule(person, controller, sched, current_schedule)) - _LOGGER.debug("Added %s", entities) return entities @@ -185,11 +183,6 @@ class RachioSwitch(RachioDevice, SwitchEntity): super().__init__(controller) self._state = None - @property - def name(self) -> str: - """Get a name for this switch.""" - return f"Switch on {self._controller.name}" - @property def is_on(self) -> bool: """Return whether the switch is currently on.""" @@ -213,21 +206,15 @@ class RachioSwitch(RachioDevice, SwitchEntity): class RachioStandbySwitch(RachioSwitch): """Representation of a standby status/button.""" - @property - def name(self) -> str: - """Return the name of the standby switch.""" - return f"{self._controller.name} in standby mode" + _attr_has_entity_name = True + _attr_translation_key = "standby" + _attr_icon = "mdi:power" @property def unique_id(self) -> str: """Return a unique id by combining controller id and purpose.""" return f"{self._controller.controller_id}-standby" - @property - def icon(self) -> str: - """Return an icon for the standby switch.""" - return "mdi:power" - @callback def _async_handle_update(self, *args, **kwargs) -> None: """Update the state using webhook data.""" @@ -263,26 +250,20 @@ class RachioStandbySwitch(RachioSwitch): class RachioRainDelay(RachioSwitch): """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): """Set up a Rachio rain delay switch.""" self._cancel_update = None super().__init__(controller) - @property - def name(self) -> str: - """Return the name of the switch.""" - return f"{self._controller.name} rain delay" - @property def unique_id(self) -> str: """Return a unique id by combining controller id and purpose.""" return f"{self._controller.controller_id}-delay" - @property - def icon(self) -> str: - """Return an icon for rain delay.""" - return "mdi:camera-timer" - @callback def _async_handle_update(self, *args, **kwargs) -> None: """Update the state using webhook data."""