Add enum sensor to Vogel's MotionMount integration (#108643)

Add enum sensor entity
pull/108910/head
RJPoelstra 2024-01-28 15:02:39 +01:00 committed by GitHub
parent a2d707442a
commit 9413d15c25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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