Motion Blinds upgrade to local push (#44391)
* Motion Blinds upgrade to local push
This commit is contained in:
parent
769513d6a8
commit
82f9de31b1
10 changed files with 136 additions and 24 deletions
|
@ -9,6 +9,7 @@ from homeassistant.const import (
|
|||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
|
@ -71,6 +72,11 @@ class MotionBatterySensor(CoordinatorEntity, Entity):
|
|||
"""Return the name of the blind battery sensor."""
|
||||
return f"{self._blind.blind_type}-battery-{self._blind.mac[12:]}"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
return self._blind.available
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
|
@ -91,6 +97,21 @@ class MotionBatterySensor(CoordinatorEntity, Entity):
|
|||
"""Return device specific state attributes."""
|
||||
return {ATTR_BATTERY_VOLTAGE: self._blind.battery_voltage}
|
||||
|
||||
@callback
|
||||
def push_callback(self):
|
||||
"""Update entity state when a push has been received."""
|
||||
self.schedule_update_ha_state(force_refresh=False)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to multicast pushes."""
|
||||
self._blind.Register_callback(self.unique_id, self.push_callback)
|
||||
await super().async_added_to_hass()
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Unsubscribe when removed."""
|
||||
self._blind.Remove_callback(self.unique_id)
|
||||
await super().async_will_remove_from_hass()
|
||||
|
||||
|
||||
class MotionTDBUBatterySensor(MotionBatterySensor):
|
||||
"""
|
||||
|
@ -160,6 +181,11 @@ class MotionSignalStrengthSensor(CoordinatorEntity, Entity):
|
|||
return "Motion gateway signal strength"
|
||||
return f"{self._device.blind_type} signal strength - {self._device.mac[12:]}"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
return self._device.available
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
|
@ -179,3 +205,18 @@ class MotionSignalStrengthSensor(CoordinatorEntity, Entity):
|
|||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._device.RSSI
|
||||
|
||||
@callback
|
||||
def push_callback(self):
|
||||
"""Update entity state when a push has been received."""
|
||||
self.schedule_update_ha_state(force_refresh=False)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to multicast pushes."""
|
||||
self._device.Register_callback(self.unique_id, self.push_callback)
|
||||
await super().async_added_to_hass()
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Unsubscribe when removed."""
|
||||
self._device.Remove_callback(self.unique_id)
|
||||
await super().async_will_remove_from_hass()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue