From f72efa961811f51f56117f0404a137ac14591e88 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 14 Feb 2024 17:21:47 +0100 Subject: [PATCH] Add entity translations to OralB (#97402) * Make bluetooth use the translation from the entity description * Add entity translations to OralB * Remove links to other platforms * Remove links to other platforms * Remove links to other platforms * Add test * Use is * Fix tests * Update homeassistant/components/oralb/strings.json --- homeassistant/components/oralb/sensor.py | 17 +++++++++------ homeassistant/components/oralb/strings.json | 19 +++++++++++++++++ tests/components/oralb/test_sensor.py | 23 ++++++++------------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/oralb/sensor.py b/homeassistant/components/oralb/sensor.py index c7cdaddf382..f743122d0cb 100644 --- a/homeassistant/components/oralb/sensor.py +++ b/homeassistant/components/oralb/sensor.py @@ -38,23 +38,31 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = { ), OralBSensor.SECTOR: SensorEntityDescription( key=OralBSensor.SECTOR, + translation_key="sector", entity_category=EntityCategory.DIAGNOSTIC, ), OralBSensor.NUMBER_OF_SECTORS: SensorEntityDescription( key=OralBSensor.NUMBER_OF_SECTORS, + translation_key="number_of_sectors", entity_category=EntityCategory.DIAGNOSTIC, ), OralBSensor.SECTOR_TIMER: SensorEntityDescription( key=OralBSensor.SECTOR_TIMER, + translation_key="sector_timer", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, ), OralBSensor.TOOTHBRUSH_STATE: SensorEntityDescription( - key=OralBSensor.TOOTHBRUSH_STATE + key=OralBSensor.TOOTHBRUSH_STATE, + name=None, + ), + OralBSensor.PRESSURE: SensorEntityDescription( + key=OralBSensor.PRESSURE, + translation_key="pressure", ), - OralBSensor.PRESSURE: SensorEntityDescription(key=OralBSensor.PRESSURE), OralBSensor.MODE: SensorEntityDescription( key=OralBSensor.MODE, + translation_key="mode", entity_category=EntityCategory.DIAGNOSTIC, ), OralBSensor.SIGNAL_STRENGTH: SensorEntityDescription( @@ -94,10 +102,7 @@ def sensor_update_to_bluetooth_data_update( device_key_to_bluetooth_entity_key(device_key): sensor_values.native_value for device_key, sensor_values in sensor_update.entity_values.items() }, - entity_names={ - device_key_to_bluetooth_entity_key(device_key): sensor_values.name - for device_key, sensor_values in sensor_update.entity_values.items() - }, + entity_names={}, ) diff --git a/homeassistant/components/oralb/strings.json b/homeassistant/components/oralb/strings.json index d1d544c2381..f60fd56a9a4 100644 --- a/homeassistant/components/oralb/strings.json +++ b/homeassistant/components/oralb/strings.json @@ -18,5 +18,24 @@ "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } + }, + "entity": { + "sensor": { + "sector": { + "name": "Sector" + }, + "number_of_sectors": { + "name": "Number of sectors" + }, + "sector_timer": { + "name": "Sector timer" + }, + "pressure": { + "name": "Pressure" + }, + "mode": { + "name": "Brushing mode" + } + } } } diff --git a/tests/components/oralb/test_sensor.py b/tests/components/oralb/test_sensor.py index b48ccad2fe2..b1210712e7a 100644 --- a/tests/components/oralb/test_sensor.py +++ b/tests/components/oralb/test_sensor.py @@ -46,15 +46,10 @@ async def test_sensors( await hass.async_block_till_done() assert len(hass.states.async_all("sensor")) == 9 - toothbrush_sensor = hass.states.get( - "sensor.smart_series_7000_48be_toothbrush_state" - ) + toothbrush_sensor = hass.states.get("sensor.smart_series_7000_48be") toothbrush_sensor_attrs = toothbrush_sensor.attributes assert toothbrush_sensor.state == "running" - assert ( - toothbrush_sensor_attrs[ATTR_FRIENDLY_NAME] - == "Smart Series 7000 48BE Toothbrush State" - ) + assert toothbrush_sensor_attrs[ATTR_FRIENDLY_NAME] == "Smart Series 7000 48BE" assert ATTR_ASSUMED_STATE not in toothbrush_sensor_attrs assert await hass.config_entries.async_unload(entry.entry_id) @@ -77,10 +72,7 @@ async def test_sensors( await hass.async_block_till_done() # All of these devices are sleepy so we should still be available - toothbrush_sensor = hass.states.get( - "sensor.smart_series_7000_48be_toothbrush_state" - ) - toothbrush_sensor_attrs = toothbrush_sensor.attributes + toothbrush_sensor = hass.states.get("sensor.smart_series_7000_48be") assert toothbrush_sensor.state == "running" @@ -104,10 +96,12 @@ async def test_sensors_io_series_4( await hass.async_block_till_done() assert len(hass.states.async_all("sensor")) == 9 - toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_mode") + toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_brushing_mode") toothbrush_sensor_attrs = toothbrush_sensor.attributes assert toothbrush_sensor.state == "gum care" - assert toothbrush_sensor_attrs[ATTR_FRIENDLY_NAME] == "IO Series 4 48BE Mode" + assert ( + toothbrush_sensor_attrs[ATTR_FRIENDLY_NAME] == "IO Series 4 48BE Brushing mode" + ) assert ATTR_ASSUMED_STATE not in toothbrush_sensor_attrs # Fast-forward time without BLE advertisements @@ -131,7 +125,7 @@ async def test_sensors_io_series_4( assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_mode") + toothbrush_sensor = hass.states.get("sensor.io_series_4_48be_brushing_mode") # Sleepy devices should keep their state over time assert toothbrush_sensor.state == "gum care" toothbrush_sensor_attrs = toothbrush_sensor.attributes @@ -157,6 +151,7 @@ async def test_sensors_battery(hass: HomeAssistant) -> None: bat_sensor = hass.states.get("sensor.io_series_6_7_1dcf_battery") assert bat_sensor.state == "49" + assert bat_sensor.name == "IO Series 6/7 1DCF Battery" assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done()