Add binary_sensor platform to SenseME (#63660)

This commit is contained in:
J. Nick Koston 2022-01-08 19:52:51 -10:00 committed by GitHub
parent 34a967c48a
commit 8e0b124875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 2 deletions

View File

@ -951,6 +951,7 @@ omit =
homeassistant/components/sensehat/light.py
homeassistant/components/sensehat/sensor.py
homeassistant/components/senseme/__init__.py
homeassistant/components/senseme/binary_sensor.py
homeassistant/components/senseme/discovery.py
homeassistant/components/senseme/entity.py
homeassistant/components/senseme/fan.py

View File

@ -0,0 +1,41 @@
"""Support for Big Ass Fans SenseME occupancy sensor."""
from __future__ import annotations
from aiosenseme import SensemeDevice
from homeassistant import config_entries
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import SensemeEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: config_entries.ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up SenseME occupancy sensors."""
device = hass.data[DOMAIN][entry.entry_id]
if device.has_sensor:
async_add_entities([HASensemeOccupancySensor(device)])
class HASensemeOccupancySensor(SensemeEntity, BinarySensorEntity):
"""Representation of a Big Ass Fans SenseME occupancy sensor."""
def __init__(self, device: SensemeDevice) -> None:
"""Initialize the entity."""
super().__init__(device, f"{device.name} Occupancy")
self._attr_unique_id = f"{self._device.uuid}-SENSOR"
self._attr_device_class = BinarySensorDeviceClass.OCCUPANCY
@callback
def _async_update_attrs(self) -> None:
"""Update attrs from device."""
self._attr_is_on = bool(self._device.motion_detected)

View File

@ -20,4 +20,4 @@ PRESET_MODE_WHOOSH = "Whoosh"
SENSEME_DIRECTION_FORWARD = "FWD"
SENSEME_DIRECTION_REVERSE = "REV"
PLATFORMS = [Platform.FAN]
PLATFORMS = [Platform.BINARY_SENSOR, Platform.FAN]

View File

@ -25,6 +25,7 @@ class SensemeEntity(Entity):
sw_version=self._device.fw_version,
suggested_area=self._device.room_name,
)
self._async_update_attrs()
@property
def extra_state_attributes(self) -> dict:

View File

@ -58,7 +58,6 @@ class HASensemeFan(SensemeEntity, FanEntity):
super().__init__(device, device.name)
self._attr_speed_count = self._device.fan_speed_max
self._attr_unique_id = f"{self._device.uuid}-FAN" # for legacy compat
self._async_update_attrs()
@callback
def _async_update_attrs(self) -> None: