From 097c7fbfef95e29a3d2ef90910f0cd15154e4471 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 22 Aug 2023 14:41:15 +0200 Subject: [PATCH] Add entity translations to Nexia (#98803) --- .../components/nexia/binary_sensor.py | 8 ++-- homeassistant/components/nexia/climate.py | 6 +-- homeassistant/components/nexia/entity.py | 15 +++---- homeassistant/components/nexia/number.py | 2 +- homeassistant/components/nexia/scene.py | 4 +- homeassistant/components/nexia/sensor.py | 28 ++++++------ homeassistant/components/nexia/strings.json | 43 +++++++++++++++++++ homeassistant/components/nexia/switch.py | 5 ++- tests/components/nexia/test_binary_sensor.py | 4 +- tests/components/nexia/test_init.py | 2 +- tests/components/nexia/test_sensor.py | 18 ++++---- 11 files changed, 90 insertions(+), 45 deletions(-) diff --git a/homeassistant/components/nexia/binary_sensor.py b/homeassistant/components/nexia/binary_sensor.py index 1b398610ac2..02c3fef1162 100644 --- a/homeassistant/components/nexia/binary_sensor.py +++ b/homeassistant/components/nexia/binary_sensor.py @@ -23,7 +23,7 @@ async def async_setup_entry( thermostat = nexia_home.get_thermostat_by_id(thermostat_id) entities.append( NexiaBinarySensor( - coordinator, thermostat, "is_blower_active", "Blower Active" + coordinator, thermostat, "is_blower_active", "blower_active" ) ) if thermostat.has_emergency_heat(): @@ -32,7 +32,7 @@ async def async_setup_entry( coordinator, thermostat, "is_emergency_heat_active", - "Emergency Heat Active", + "emergency_heat_active", ) ) @@ -42,16 +42,16 @@ async def async_setup_entry( class NexiaBinarySensor(NexiaThermostatEntity, BinarySensorEntity): """Provices Nexia BinarySensor support.""" - def __init__(self, coordinator, thermostat, sensor_call, sensor_name): + def __init__(self, coordinator, thermostat, sensor_call, translation_key): """Initialize the nexia sensor.""" super().__init__( coordinator, thermostat, - name=f"{thermostat.get_name()} {sensor_name}", unique_id=f"{thermostat.thermostat_id}_{sensor_call}", ) self._call = sensor_call self._state = None + self._attr_translation_key = translation_key @property def is_on(self): diff --git a/homeassistant/components/nexia/climate.py b/homeassistant/components/nexia/climate.py index fe31263a86c..e331108f6ba 100644 --- a/homeassistant/components/nexia/climate.py +++ b/homeassistant/components/nexia/climate.py @@ -150,13 +150,13 @@ async def async_setup_entry( class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity): """Provides Nexia Climate support.""" + _attr_name = None + def __init__( self, coordinator: NexiaDataUpdateCoordinator, zone: NexiaThermostatZone ) -> None: """Initialize the thermostat.""" - super().__init__( - coordinator, zone, name=zone.get_name(), unique_id=zone.zone_id - ) + super().__init__(coordinator, zone, zone.zone_id) unit = self._thermostat.get_unit() min_humidity, max_humidity = self._thermostat.get_humidity_setpoint_limits() min_setpoint, max_setpoint = self._thermostat.get_setpoint_limits() diff --git a/homeassistant/components/nexia/entity.py b/homeassistant/components/nexia/entity.py index 2a09ec877c8..dfb2366d34a 100644 --- a/homeassistant/components/nexia/entity.py +++ b/homeassistant/components/nexia/entity.py @@ -31,21 +31,20 @@ class NexiaEntity(CoordinatorEntity[NexiaDataUpdateCoordinator]): _attr_attribution = ATTRIBUTION - def __init__( - self, coordinator: NexiaDataUpdateCoordinator, name: str, unique_id: str - ) -> None: + def __init__(self, coordinator: NexiaDataUpdateCoordinator, unique_id: str) -> None: """Initialize the entity.""" super().__init__(coordinator) self._attr_unique_id = unique_id - self._attr_name = name class NexiaThermostatEntity(NexiaEntity): """Base class for nexia devices attached to a thermostat.""" - def __init__(self, coordinator, thermostat, name, unique_id): + _attr_has_entity_name = True + + def __init__(self, coordinator, thermostat, unique_id): """Initialize the entity.""" - super().__init__(coordinator, name, unique_id) + super().__init__(coordinator, unique_id) self._thermostat: NexiaThermostat = thermostat self._attr_device_info = DeviceInfo( configuration_url=self.coordinator.nexia_home.root_url, @@ -89,9 +88,9 @@ class NexiaThermostatEntity(NexiaEntity): class NexiaThermostatZoneEntity(NexiaThermostatEntity): """Base class for nexia devices attached to a thermostat.""" - def __init__(self, coordinator, zone, name, unique_id): + def __init__(self, coordinator, zone, unique_id): """Initialize the entity.""" - super().__init__(coordinator, zone.thermostat, name, unique_id) + super().__init__(coordinator, zone.thermostat, unique_id) self._zone: NexiaThermostatZone = zone zone_name = self._zone.get_name() self._attr_device_info |= { diff --git a/homeassistant/components/nexia/number.py b/homeassistant/components/nexia/number.py index acb99c2ed01..b44c6a4c48f 100644 --- a/homeassistant/components/nexia/number.py +++ b/homeassistant/components/nexia/number.py @@ -42,6 +42,7 @@ class NexiaFanSpeedEntity(NexiaThermostatEntity, NumberEntity): _attr_native_unit_of_measurement = PERCENTAGE _attr_icon = "mdi:fan" + _attr_translation_key = "fan_speed" def __init__( self, @@ -53,7 +54,6 @@ class NexiaFanSpeedEntity(NexiaThermostatEntity, NumberEntity): super().__init__( coordinator, thermostat, - name=f"{thermostat.get_name()} Fan speed", unique_id=f"{thermostat.thermostat_id}_fan_speed_setpoint", ) min_value, max_value = valid_range diff --git a/homeassistant/components/nexia/scene.py b/homeassistant/components/nexia/scene.py index 941785f8221..3a21c61badd 100644 --- a/homeassistant/components/nexia/scene.py +++ b/homeassistant/components/nexia/scene.py @@ -43,9 +43,9 @@ class NexiaAutomationScene(NexiaEntity, Scene): """Initialize the automation scene.""" super().__init__( coordinator, - name=automation.name, - unique_id=automation.automation_id, + automation.automation_id, ) + self._attr_name = automation.name self._automation: NexiaAutomation = automation self._attr_extra_state_attributes = {ATTR_DESCRIPTION: automation.description} diff --git a/homeassistant/components/nexia/sensor.py b/homeassistant/components/nexia/sensor.py index a67ac681199..79e07bc71b4 100644 --- a/homeassistant/components/nexia/sensor.py +++ b/homeassistant/components/nexia/sensor.py @@ -40,7 +40,7 @@ async def async_setup_entry( coordinator, thermostat, "get_system_status", - "System Status", + "system_status", None, None, None, @@ -52,7 +52,7 @@ async def async_setup_entry( coordinator, thermostat, "get_air_cleaner_mode", - "Air Cleaner Mode", + "air_cleaner_mode", None, None, None, @@ -65,7 +65,7 @@ async def async_setup_entry( coordinator, thermostat, "get_current_compressor_speed", - "Current Compressor Speed", + "current_compressor_speed", None, PERCENTAGE, SensorStateClass.MEASUREMENT, @@ -77,7 +77,7 @@ async def async_setup_entry( coordinator, thermostat, "get_requested_compressor_speed", - "Requested Compressor Speed", + "requested_compressor_speed", None, PERCENTAGE, SensorStateClass.MEASUREMENT, @@ -95,7 +95,7 @@ async def async_setup_entry( coordinator, thermostat, "get_outdoor_temperature", - "Outdoor Temperature", + "outdoor_temperature", SensorDeviceClass.TEMPERATURE, unit, SensorStateClass.MEASUREMENT, @@ -108,7 +108,7 @@ async def async_setup_entry( coordinator, thermostat, "get_relative_humidity", - "Relative Humidity", + None, SensorDeviceClass.HUMIDITY, PERCENTAGE, SensorStateClass.MEASUREMENT, @@ -129,7 +129,7 @@ async def async_setup_entry( coordinator, zone, "get_temperature", - "Temperature", + None, SensorDeviceClass.TEMPERATURE, unit, SensorStateClass.MEASUREMENT, @@ -139,7 +139,7 @@ async def async_setup_entry( # Zone Status entities.append( NexiaThermostatZoneSensor( - coordinator, zone, "get_status", "Zone Status", None, None, None + coordinator, zone, "get_status", "zone_status", None, None, None ) ) # Setpoint Status @@ -148,7 +148,7 @@ async def async_setup_entry( coordinator, zone, "get_setpoint_status", - "Zone Setpoint Status", + "zone_setpoint_status", None, None, None, @@ -166,7 +166,7 @@ class NexiaThermostatSensor(NexiaThermostatEntity, SensorEntity): coordinator, thermostat, sensor_call, - sensor_name, + translation_key, sensor_class, sensor_unit, state_class, @@ -176,7 +176,6 @@ class NexiaThermostatSensor(NexiaThermostatEntity, SensorEntity): super().__init__( coordinator, thermostat, - name=f"{thermostat.get_name()} {sensor_name}", unique_id=f"{thermostat.thermostat_id}_{sensor_call}", ) self._call = sensor_call @@ -184,6 +183,8 @@ class NexiaThermostatSensor(NexiaThermostatEntity, SensorEntity): self._attr_device_class = sensor_class self._attr_native_unit_of_measurement = sensor_unit self._attr_state_class = state_class + if translation_key is not None: + self._attr_translation_key = translation_key @property def native_value(self): @@ -204,7 +205,7 @@ class NexiaThermostatZoneSensor(NexiaThermostatZoneEntity, SensorEntity): coordinator, zone, sensor_call, - sensor_name, + translation_key, sensor_class, sensor_unit, state_class, @@ -215,7 +216,6 @@ class NexiaThermostatZoneSensor(NexiaThermostatZoneEntity, SensorEntity): super().__init__( coordinator, zone, - name=f"{zone.get_name()} {sensor_name}", unique_id=f"{zone.zone_id}_{sensor_call}", ) self._call = sensor_call @@ -223,6 +223,8 @@ class NexiaThermostatZoneSensor(NexiaThermostatZoneEntity, SensorEntity): self._attr_device_class = sensor_class self._attr_native_unit_of_measurement = sensor_unit self._attr_state_class = state_class + if translation_key is not None: + self._attr_translation_key = translation_key @property def native_value(self): diff --git a/homeassistant/components/nexia/strings.json b/homeassistant/components/nexia/strings.json index f3d343ffda3..9e49f4bb793 100644 --- a/homeassistant/components/nexia/strings.json +++ b/homeassistant/components/nexia/strings.json @@ -18,6 +18,49 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } }, + "entity": { + "binary_sensor": { + "blower_active": { + "name": "Blower active" + }, + "emergency_heat_active": { + "name": "Emergency heat active" + } + }, + "number": { + "fan_speed": { + "name": "Fan speed" + } + }, + "sensor": { + "system_status": { + "name": "System status" + }, + "air_cleaner_mode": { + "name": "Air cleaner mode" + }, + "current_compressor_speed": { + "name": "Current compressor speed" + }, + "requested_compressor_speed": { + "name": "Requested compressor speed" + }, + "outdoor_temperature": { + "name": "Outdoor temperature" + }, + "zone_status": { + "name": "Zone status" + }, + "zone_setpoint_status": { + "name": "Zone setpoint status" + } + }, + "switch": { + "hold": { + "name": "Hold" + } + } + }, "services": { "set_aircleaner_mode": { "name": "Set air cleaner mode", diff --git a/homeassistant/components/nexia/switch.py b/homeassistant/components/nexia/switch.py index 643a4d585c4..7f191d39c73 100644 --- a/homeassistant/components/nexia/switch.py +++ b/homeassistant/components/nexia/switch.py @@ -39,13 +39,14 @@ async def async_setup_entry( class NexiaHoldSwitch(NexiaThermostatZoneEntity, SwitchEntity): """Provides Nexia hold switch support.""" + _attr_translation_key = "hold" + def __init__( self, coordinator: NexiaDataUpdateCoordinator, zone: NexiaThermostatZone ) -> None: """Initialize the hold mode switch.""" - switch_name = f"{zone.get_name()} Hold" zone_id = zone.zone_id - super().__init__(coordinator, zone, name=switch_name, unique_id=zone_id) + super().__init__(coordinator, zone, zone_id) @property def is_on(self) -> bool: diff --git a/tests/components/nexia/test_binary_sensor.py b/tests/components/nexia/test_binary_sensor.py index 78753383b03..f59e968d634 100644 --- a/tests/components/nexia/test_binary_sensor.py +++ b/tests/components/nexia/test_binary_sensor.py @@ -14,7 +14,7 @@ async def test_create_binary_sensors(hass: HomeAssistant) -> None: assert state.state == STATE_ON expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Master Suite Blower Active", + "friendly_name": "Master Suite Blower active", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -26,7 +26,7 @@ async def test_create_binary_sensors(hass: HomeAssistant) -> None: assert state.state == STATE_OFF expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Downstairs East Wing Blower Active", + "friendly_name": "Downstairs East Wing Blower active", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears diff --git a/tests/components/nexia/test_init.py b/tests/components/nexia/test_init.py index 5409181f00e..f920592f8a6 100644 --- a/tests/components/nexia/test_init.py +++ b/tests/components/nexia/test_init.py @@ -53,7 +53,7 @@ async def test_device_remove_devices( is False ) - entity = registry.entities["sensor.master_suite_relative_humidity"] + entity = registry.entities["sensor.master_suite_humidity"] live_thermostat_device_entry = device_registry.async_get(entity.device_id) assert ( await remove_device( diff --git a/tests/components/nexia/test_sensor.py b/tests/components/nexia/test_sensor.py index 4d693261a9d..23a92af71c8 100644 --- a/tests/components/nexia/test_sensor.py +++ b/tests/components/nexia/test_sensor.py @@ -29,7 +29,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: assert state.state == "Permanent Hold" expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Nick Office Zone Setpoint Status", + "friendly_name": "Nick Office Zone setpoint status", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -42,7 +42,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Nick Office Zone Status", + "friendly_name": "Nick Office Zone status", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -55,7 +55,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Master Suite Air Cleaner Mode", + "friendly_name": "Master Suite Air cleaner mode", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -68,7 +68,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Master Suite Current Compressor Speed", + "friendly_name": "Master Suite Current compressor speed", "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case @@ -83,7 +83,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", "device_class": "temperature", - "friendly_name": "Master Suite Outdoor Temperature", + "friendly_name": "Master Suite Outdoor temperature", "unit_of_measurement": UnitOfTemperature.CELSIUS, } # Only test for a subset of attributes in case @@ -92,13 +92,13 @@ async def test_create_sensors(hass: HomeAssistant) -> None: state.attributes[key] == expected_attributes[key] for key in expected_attributes ) - state = hass.states.get("sensor.master_suite_relative_humidity") + state = hass.states.get("sensor.master_suite_humidity") assert state.state == "52.0" expected_attributes = { "attribution": "Data provided by Trane Technologies", "device_class": "humidity", - "friendly_name": "Master Suite Relative Humidity", + "friendly_name": "Master Suite Humidity", "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case @@ -112,7 +112,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Master Suite Requested Compressor Speed", + "friendly_name": "Master Suite Requested compressor speed", "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case @@ -126,7 +126,7 @@ async def test_create_sensors(hass: HomeAssistant) -> None: expected_attributes = { "attribution": "Data provided by Trane Technologies", - "friendly_name": "Master Suite System Status", + "friendly_name": "Master Suite System status", } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears