Lots of changes and modernization. WIP
This commit is contained in:
@@ -1,60 +1,25 @@
|
||||
from datetime import datetime
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
ATTR_BATTERY_CHARGING,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
)
|
||||
from homeassistant.components.binary_sensor import DEVICE_CLASS_MOTION
|
||||
|
||||
from .helpers import setup_platform, BrowserModEntity
|
||||
|
||||
PLATFORM = "binary_sensor"
|
||||
from .const import DOMAIN, DATA_ADDERS
|
||||
from .helpers import BrowserModEntity2
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModSensor)
|
||||
|
||||
async def async_setup_platform(hass, config_entry, async_add_entities, discoveryInfo = None):
|
||||
hass.data[DOMAIN][DATA_ADDERS]["binary_sensor"] = async_add_entities
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
await async_setup_platform(hass, {}, async_add_entities)
|
||||
|
||||
|
||||
class BrowserModSensor(BrowserModEntity):
|
||||
domain = PLATFORM
|
||||
class BrowserBinarySensor(BrowserModEntity2, BinarySensorEntity):
|
||||
|
||||
def __init__(self, hass, connection, deviceID, alias=None):
|
||||
super().__init__(hass, connection, deviceID, alias)
|
||||
self.last_seen = None
|
||||
|
||||
def updated(self):
|
||||
self.last_seen = datetime.now()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if not self.connection.connection:
|
||||
return STATE_UNAVAILABLE
|
||||
if self.data.get("motion", False):
|
||||
return STATE_ON
|
||||
return STATE_OFF
|
||||
def __init__(self, coordinator, deviceID, parameter, name):
|
||||
super().__init__(coordinator, deviceID, name)
|
||||
self.parameter = parameter
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return not self.data.get("motion", False)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
return DEVICE_CLASS_MOTION
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"last_seen": self.last_seen,
|
||||
ATTR_BATTERY_LEVEL: self.data.get("battery", None),
|
||||
ATTR_BATTERY_CHARGING: self.data.get("charging", None),
|
||||
**self.data,
|
||||
}
|
||||
data = self._data
|
||||
data = data.get("browser", {})
|
||||
data = data.get(self.parameter, None)
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user