Add enum sensor to Vogel's MotionMount integration (#108643)
Add enum sensor entitypull/108910/head
parent
a2d707442a
commit
9413d15c25
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue