diff --git a/.coveragerc b/.coveragerc index 13cab09e29468b7b8cd0cebf152225e73a10252e..1d291610bc18ed4c9bd55cafe83c4ca9280b14aa 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 5c661a77955bf619a93bd9f9204685e0c3097fed..6f62a0731b69afd768f8b4945919004434f62f48 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 0000000000000000000000000000000000000000..ed3cbd7d38bed2b75a73921a8ff77af2bec913ea --- /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 94859dc90e33c1c4121501f8c260bb9b021495a0..39f7c53db35a9a52f774075d5e8ad5e8d3611b3a 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",