Add binary sensor to MotionMount integration (#107659)

* Add binary sensor for `isMoving`

* Sort platforms alphabetically

* Update doc strings
This commit is contained in:
RJPoelstra 2024-01-19 16:01:20 +01:00 committed by GitHub
parent 4a0b6af8c1
commit 298b0d1105
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 4 deletions

View file

@ -762,6 +762,7 @@ omit =
homeassistant/components/motion_blinds/entity.py
homeassistant/components/motion_blinds/sensor.py
homeassistant/components/motionmount/__init__.py
homeassistant/components/motionmount/binary_sensor.py
homeassistant/components/motionmount/entity.py
homeassistant/components/motionmount/number.py
homeassistant/components/motionmount/select.py

View file

@ -13,10 +13,7 @@ from homeassistant.helpers.device_registry import format_mac
from .const import DOMAIN, EMPTY_MAC
PLATFORMS: list[Platform] = [
Platform.NUMBER,
Platform.SELECT,
]
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.NUMBER, Platform.SELECT]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

View file

@ -0,0 +1,39 @@
"""Support for MotionMount binary sensors."""
import motionmount
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
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([MotionMountMovingSensor(mm, entry)])
class MotionMountMovingSensor(MotionMountEntity, BinarySensorEntity):
"""The moving sensor of a MotionMount."""
_attr_device_class = BinarySensorDeviceClass.MOVING
_attr_translation_key = "motionmount_is_moving"
def __init__(self, mm: motionmount.MotionMount, config_entry: ConfigEntry) -> None:
"""Initialize moving binary sensor entity."""
super().__init__(mm, config_entry)
self._attr_unique_id = f"{self._base_unique_id}-moving"
@property
def is_on(self) -> bool:
"""Get on status."""
return self.mm.is_moving or False

View file

@ -25,6 +25,11 @@
}
},
"entity": {
"binary_sensor": {
"motionmount_is_moving": {
"name": "Moving"
}
},
"number": {
"motionmount_extension": {
"name": "Extension"