mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-09-27 18:22:41 +00:00
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
![]() |
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
|