From dca7083026f7a653d57a26fceb609ec1f95962ba Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 5 Mar 2024 15:32:12 +0100 Subject: [PATCH] Add icon translations to Uptimerobot (#112336) * Add icon translations to Uptimerobot * Add icon translations to Uptimerobot --- .../components/uptimerobot/icons.json | 20 ++++++++++++++ .../components/uptimerobot/sensor.py | 27 +++++-------------- .../components/uptimerobot/switch.py | 2 +- tests/components/uptimerobot/test_sensor.py | 9 +++---- tests/components/uptimerobot/test_switch.py | 5 ++-- 5 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 homeassistant/components/uptimerobot/icons.json diff --git a/homeassistant/components/uptimerobot/icons.json b/homeassistant/components/uptimerobot/icons.json new file mode 100644 index 00000000000..36bd3732f41 --- /dev/null +++ b/homeassistant/components/uptimerobot/icons.json @@ -0,0 +1,20 @@ +{ + "entity": { + "sensor": { + "monitor_status": { + "default": "mdi:television", + "state": { + "pause": "mdi:television-pause", + "up": "mdi:television-shimmer", + "seems_down": "mdi:television-off", + "down": "mdi:television-off" + } + } + }, + "switch": { + "monitor_status": { + "default": "mdi:cog" + } + } + } +} diff --git a/homeassistant/components/uptimerobot/sensor.py b/homeassistant/components/uptimerobot/sensor.py index 4ae40bf4134..c1e4db0fef7 100644 --- a/homeassistant/components/uptimerobot/sensor.py +++ b/homeassistant/components/uptimerobot/sensor.py @@ -1,8 +1,6 @@ """UptimeRobot sensor platform.""" from __future__ import annotations -from typing import TypedDict - from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, @@ -17,20 +15,12 @@ from .const import DOMAIN from .coordinator import UptimeRobotDataUpdateCoordinator from .entity import UptimeRobotEntity - -class StatusValue(TypedDict): - """Sensor details.""" - - value: str - icon: str - - SENSORS_INFO = { - 0: StatusValue(value="pause", icon="mdi:television-pause"), - 1: StatusValue(value="not_checked_yet", icon="mdi:television"), - 2: StatusValue(value="up", icon="mdi:television-shimmer"), - 8: StatusValue(value="seems_down", icon="mdi:television-off"), - 9: StatusValue(value="down", icon="mdi:television-off"), + 0: "pause", + 1: "not_checked_yet", + 2: "up", + 8: "seems_down", + 9: "down", } @@ -63,9 +53,4 @@ class UptimeRobotSensor(UptimeRobotEntity, SensorEntity): @property def native_value(self) -> str: """Return the status of the monitor.""" - return SENSORS_INFO[self.monitor.status]["value"] - - @property - def icon(self) -> str: - """Return the status of the monitor.""" - return SENSORS_INFO[self.monitor.status]["icon"] + return SENSORS_INFO[self.monitor.status] diff --git a/homeassistant/components/uptimerobot/switch.py b/homeassistant/components/uptimerobot/switch.py index 3406c9fe21a..e76418e3300 100644 --- a/homeassistant/components/uptimerobot/switch.py +++ b/homeassistant/components/uptimerobot/switch.py @@ -40,7 +40,7 @@ async def async_setup_entry( class UptimeRobotSwitch(UptimeRobotEntity, SwitchEntity): """Representation of a UptimeRobot switch.""" - _attr_icon = "mdi:cog" + _attr_translation_key = "monitor_status" @property def is_on(self) -> bool: diff --git a/tests/components/uptimerobot/test_sensor.py b/tests/components/uptimerobot/test_sensor.py index 110ea07c202..8cee33c1052 100644 --- a/tests/components/uptimerobot/test_sensor.py +++ b/tests/components/uptimerobot/test_sensor.py @@ -19,17 +19,14 @@ from .common import ( from tests.common import async_fire_time_changed -SENSOR_ICON = "mdi:television-shimmer" - async def test_presentation(hass: HomeAssistant) -> None: - """Test the presenstation of UptimeRobot sensors.""" + """Test the presentation of UptimeRobot sensors.""" await setup_uptimerobot_integration(hass) entity = hass.states.get(UPTIMEROBOT_SENSOR_TEST_ENTITY) assert entity.state == STATE_UP - assert entity.attributes["icon"] == SENSOR_ICON assert entity.attributes["target"] == MOCK_UPTIMEROBOT_MONITOR["url"] assert entity.attributes["device_class"] == SensorDeviceClass.ENUM assert entity.attributes["options"] == [ @@ -41,8 +38,8 @@ async def test_presentation(hass: HomeAssistant) -> None: ] -async def test_unaviable_on_update_failure(hass: HomeAssistant) -> None: - """Test entity unaviable on update failure.""" +async def test_unavailable_on_update_failure(hass: HomeAssistant) -> None: + """Test entity unavailable on update failure.""" await setup_uptimerobot_integration(hass) entity = hass.states.get(UPTIMEROBOT_SENSOR_TEST_ENTITY) diff --git a/tests/components/uptimerobot/test_switch.py b/tests/components/uptimerobot/test_switch.py index f10a202f208..7929879db19 100644 --- a/tests/components/uptimerobot/test_switch.py +++ b/tests/components/uptimerobot/test_switch.py @@ -28,18 +28,17 @@ from tests.common import MockConfigEntry async def test_presentation(hass: HomeAssistant) -> None: - """Test the presenstation of UptimeRobot sensors.""" + """Test the presentation of UptimeRobot switches.""" await setup_uptimerobot_integration(hass) entity = hass.states.get(UPTIMEROBOT_SWITCH_TEST_ENTITY) assert entity.state == STATE_ON - assert entity.attributes["icon"] == "mdi:cog" assert entity.attributes["target"] == MOCK_UPTIMEROBOT_MONITOR["url"] async def test_switch_off(hass: HomeAssistant) -> None: - """Test entity unaviable on update failure.""" + """Test entity unavailable on update failure.""" mock_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA) mock_entry.add_to_hass(hass)