Add icon translations to Uptimerobot (#112336)

* Add icon translations to Uptimerobot

* Add icon translations to Uptimerobot
This commit is contained in:
Joost Lekkerkerker 2024-03-05 15:32:12 +01:00 committed by GitHub
parent 4fcc446255
commit dca7083026
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 31 deletions

View File

@ -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"
}
}
}
}

View File

@ -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]

View File

@ -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:

View File

@ -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)

View File

@ -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)