init commit

This commit is contained in:
unknown
2023-09-02 16:30:03 +08:00
parent 6554430ac4
commit 86cd072738
18 changed files with 1635 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
from homeassistant.helpers.entity import Entity
from .const import DOMAIN
class MideaEntity(Entity):
def __init__(self, device, entity_key: str):
self._device = device
self._device.register_update(self.update_state)
self._entity_key = entity_key
self._unique_id = f"{DOMAIN}.{self._device.device_id}_{entity_key}"
self.entity_id = self._unique_id
self._device_name = self._device.name
@property
def device(self):
return self._device
@property
def device_info(self):
return {
"manufacturer": "Midea",
"model": self._device.model,
"identifiers": {(DOMAIN, self._device.device_id)},
"name": self._device_name
}
@property
def unique_id(self):
return self._unique_id
@property
def should_poll(self):
return False
@property
def state(self):
return self._device.get_attribute(self._entity_key)
@property
def available(self):
return self._device.connected
def update_state(self, status):
if self._entity_key in status or "connected" in status:
try:
self.schedule_update_ha_state()
except Exception as e:
pass