From 9413d15c256e92957a009f322a4700162fd1da90 Mon Sep 17 00:00:00 2001 From: RJPoelstra <36924801+RJPoelstra@users.noreply.github.com> Date: Sun, 28 Jan 2024 15:02:39 +0100 Subject: [PATCH] Add enum sensor to Vogel's MotionMount integration (#108643) Add enum sensor entity --- .coveragerc | 1 + .../components/motionmount/__init__.py | 7 ++- .../components/motionmount/sensor.py | 46 +++++++++++++++++++ .../components/motionmount/strings.json | 10 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/motionmount/sensor.py diff --git a/.coveragerc b/.coveragerc index 13cab09e294..1d291610bc1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -780,6 +780,7 @@ omit = homeassistant/components/motionmount/entity.py homeassistant/components/motionmount/number.py homeassistant/components/motionmount/select.py + homeassistant/components/motionmount/sensor.py homeassistant/components/mpd/media_player.py homeassistant/components/mqtt_room/sensor.py homeassistant/components/msteams/notify.py diff --git a/homeassistant/components/motionmount/__init__.py b/homeassistant/components/motionmount/__init__.py index 5c661a77955..6f62a0731b6 100644 --- a/homeassistant/components/motionmount/__init__.py +++ b/homeassistant/components/motionmount/__init__.py @@ -13,7 +13,12 @@ from homeassistant.helpers.device_registry import format_mac from .const import DOMAIN, EMPTY_MAC -PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.NUMBER, Platform.SELECT] +PLATFORMS: list[Platform] = [ + Platform.BINARY_SENSOR, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, +] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/motionmount/sensor.py b/homeassistant/components/motionmount/sensor.py new file mode 100644 index 00000000000..ed3cbd7d38b --- /dev/null +++ b/homeassistant/components/motionmount/sensor.py @@ -0,0 +1,46 @@ +"""Support for MotionMount sensors.""" +import motionmount + +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN +from .entity import MotionMountEntity + + +async def async_setup_entry( + hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback +) -> None: + """Set up Vogel's MotionMount from a config entry.""" + mm = hass.data[DOMAIN][entry.entry_id] + + async_add_entities((MotionMountErrorStatusSensor(mm, entry),)) + + +class MotionMountErrorStatusSensor(MotionMountEntity, SensorEntity): + """The error status sensor of a MotionMount.""" + + _attr_device_class = SensorDeviceClass.ENUM + _attr_options = ["none", "motor", "internal"] + _attr_translation_key = "motionmount_error_status" + + def __init__(self, mm: motionmount.MotionMount, config_entry: ConfigEntry) -> None: + """Initialize sensor entiry.""" + super().__init__(mm, config_entry) + self._attr_unique_id = f"{self._base_unique_id}-error-status" + + @property + def native_value(self) -> str: + """Return error status.""" + errors = self.mm.error_status or 0 + + if errors & (1 << 31): + # Only when but 31 is set are there any errors active at this moment + if errors & (1 << 10): + return "motor" + + return "internal" + + return "none" diff --git a/homeassistant/components/motionmount/strings.json b/homeassistant/components/motionmount/strings.json index 94859dc90e3..39f7c53db35 100644 --- a/homeassistant/components/motionmount/strings.json +++ b/homeassistant/components/motionmount/strings.json @@ -38,6 +38,16 @@ "name": "Turn" } }, + "sensor": { + "motionmount_error_status": { + "name": "Error Status", + "state": { + "none": "None", + "motor": "Motor", + "internal": "Internal" + } + } + }, "select": { "motionmount_preset": { "name": "Preset", -- GitLab