mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-09-28 02:32:40 +00:00
v0.0.3
This commit is contained in:
@@ -1,48 +1,45 @@
|
||||
import logging
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_ID,
|
||||
STATE_ON,
|
||||
STATE_OFF
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntity,
|
||||
BinarySensorDeviceClass
|
||||
)
|
||||
from homeassistant.const import (
|
||||
Platform,
|
||||
CONF_DEVICE_ID,
|
||||
CONF_DEVICE,
|
||||
CONF_ENTITIES
|
||||
)
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from .midea_entities import MideaEntity
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
DEVICES,
|
||||
DEVICES
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .midea_entities import MideaBinaryBaseEntity
|
||||
|
||||
|
||||
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, "status")
|
||||
binary_sensors.append(sensor)
|
||||
async_add_entities(binary_sensors)
|
||||
device = hass.data[DOMAIN][DEVICES][device_id].get(CONF_DEVICE)
|
||||
manufacturer = hass.data[DOMAIN][DEVICES][device_id].get("manufacturer")
|
||||
entities = hass.data[DOMAIN][DEVICES][device_id].get(CONF_ENTITIES).get(Platform.BINARY_SENSOR)
|
||||
devs = [MideaDeviceStatusSensorEntity(device, manufacturer,"Status", {})]
|
||||
if entities is not None:
|
||||
for entity_key, config in entities.items():
|
||||
devs.append(MideaBinarySensorEntity(device, manufacturer, entity_key, config))
|
||||
async_add_entities(devs)
|
||||
|
||||
|
||||
class MideaDeviceStatusSensor(MideaEntity):
|
||||
class MideaDeviceStatusSensorEntity(MideaBinaryBaseEntity, BinarySensorEntity):
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
return BinarySensorDeviceClass.CONNECTIVITY
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return STATE_ON if self._device.connected else STATE_OFF
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return f"{self._device_name} Status"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return "mdi:devices"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
return self.state == STATE_ON
|
||||
return self._device.connected
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
@@ -57,3 +54,7 @@ class MideaDeviceStatusSensor(MideaEntity):
|
||||
self.schedule_update_ha_state()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
class MideaBinarySensorEntity(MideaBinaryBaseEntity, BinarySensorEntity):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user