From 40d337479edc6975ac3a2a4b102ad711a49b9bcc Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 5 Dec 2022 10:36:16 +0100 Subject: [PATCH] Use enum sensor device class in UptimeRobot (#83111) --- homeassistant/components/uptimerobot/sensor.py | 10 ++++++++-- homeassistant/components/uptimerobot/strings.json | 13 +++++++++++++ .../components/uptimerobot/strings.sensor.json | 11 ----------- .../components/uptimerobot/translations/en.json | 13 +++++++++++++ tests/components/uptimerobot/test_sensor.py | 9 +++++++++ 5 files changed, 43 insertions(+), 13 deletions(-) delete mode 100644 homeassistant/components/uptimerobot/strings.sensor.json diff --git a/homeassistant/components/uptimerobot/sensor.py b/homeassistant/components/uptimerobot/sensor.py index 0e450bf24b7..ed8c42c77e7 100644 --- a/homeassistant/components/uptimerobot/sensor.py +++ b/homeassistant/components/uptimerobot/sensor.py @@ -3,7 +3,11 @@ from __future__ import annotations from typing import TypedDict -from homeassistant.components.sensor import SensorEntity, SensorEntityDescription +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorEntityDescription, +) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -44,7 +48,9 @@ async def async_setup_entry( key=str(monitor.id), name=monitor.friendly_name, entity_category=EntityCategory.DIAGNOSTIC, - device_class="uptimerobot__monitor_status", + device_class=SensorDeviceClass.ENUM, + options=["down", "not_checked_yet", "pause", "seems_down", "up"], + translation_key="monitor_status", ), monitor=monitor, ) diff --git a/homeassistant/components/uptimerobot/strings.json b/homeassistant/components/uptimerobot/strings.json index 4cca3c159ae..8fccc3cb9e9 100644 --- a/homeassistant/components/uptimerobot/strings.json +++ b/homeassistant/components/uptimerobot/strings.json @@ -28,5 +28,18 @@ "reauth_failed_existing": "Could not update the config entry, please remove the integration and set it up again.", "unknown": "[%key:common::config_flow::error::unknown%]" } + }, + "entity": { + "sensor": { + "monitor_status": { + "state": { + "down": "Down", + "not_checked_yet": "Not checked yet", + "pause": "Pause", + "seems_down": "Seems down", + "up": "Up" + } + } + } } } diff --git a/homeassistant/components/uptimerobot/strings.sensor.json b/homeassistant/components/uptimerobot/strings.sensor.json deleted file mode 100644 index 700f7cd9f4c..00000000000 --- a/homeassistant/components/uptimerobot/strings.sensor.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "state": { - "uptimerobot__monitor_status": { - "pause": "Pause", - "not_checked_yet": "Not checked yet", - "up": "Up", - "seems_down": "Seems down", - "down": "Down" - } - } -} diff --git a/homeassistant/components/uptimerobot/translations/en.json b/homeassistant/components/uptimerobot/translations/en.json index f4fe398a195..eca66f395c1 100644 --- a/homeassistant/components/uptimerobot/translations/en.json +++ b/homeassistant/components/uptimerobot/translations/en.json @@ -28,5 +28,18 @@ "description": "You need to supply the 'main' API key from UptimeRobot" } } + }, + "entity": { + "sensor": { + "monitor_status": { + "state": { + "down": "Down", + "not_checked_yet": "Not checked yet", + "pause": "Pause", + "seems_down": "Seems down", + "up": "Up" + } + } + } } } \ No newline at end of file diff --git a/tests/components/uptimerobot/test_sensor.py b/tests/components/uptimerobot/test_sensor.py index 3e833af9bd4..68b64f70e5a 100644 --- a/tests/components/uptimerobot/test_sensor.py +++ b/tests/components/uptimerobot/test_sensor.py @@ -4,6 +4,7 @@ from unittest.mock import patch from pyuptimerobot import UptimeRobotAuthenticationException +from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.uptimerobot.const import COORDINATOR_UPDATE_INTERVAL from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant @@ -30,6 +31,14 @@ async def test_presentation(hass: HomeAssistant) -> None: 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"] == [ + "down", + "not_checked_yet", + "pause", + "seems_down", + "up", + ] async def test_unaviable_on_update_failure(hass: HomeAssistant) -> None: