forked from HomeAssistant/midea-meiju-codec
init commit
This commit is contained in:
53
custom_components/midea_meiju_codec/binary_sensor.py
Normal file
53
custom_components/midea_meiju_codec/binary_sensor.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import logging
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_ID,
|
||||
STATE_ON,
|
||||
STATE_OFF
|
||||
)
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from .midea_entities import MideaEntity
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
DEVICES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
device_id = config_entry.data.get(CONF_DEVICE_ID)
|
||||
device = hass.data[DOMAIN][DEVICES].get(device_id)
|
||||
binary_sensors = []
|
||||
sensor = MideaDeviceStatusSensor(device, "online")
|
||||
binary_sensors.append(sensor)
|
||||
async_add_entities(binary_sensors)
|
||||
|
||||
|
||||
class MideaDeviceStatusSensor(MideaEntity):
|
||||
@property
|
||||
def device_class(self):
|
||||
return BinarySensorDeviceClass.CONNECTIVITY
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return STATE_ON if self._device.connected else STATE_OFF
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return self.state == STATE_ON
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
return self._device.attributes
|
||||
|
||||
def update_state(self, status):
|
||||
try:
|
||||
_LOGGER.debug("=" * 50)
|
||||
self.schedule_update_ha_state()
|
||||
_LOGGER.debug("-" * 50)
|
||||
except Exception as e:
|
||||
pass
|
Reference in New Issue
Block a user