mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add icon translations to Uptimerobot (#112336)
* Add icon translations to Uptimerobot * Add icon translations to Uptimerobot
This commit is contained in:
parent
4fcc446255
commit
dca7083026
20
homeassistant/components/uptimerobot/icons.json
Normal file
20
homeassistant/components/uptimerobot/icons.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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]
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user