mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-09-27 18:22:41 +00:00
init commit
This commit is contained in:
48
custom_components/midea_meiju_codec/midea_entities.py
Normal file
48
custom_components/midea_meiju_codec/midea_entities.py
Normal 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
|
Reference in New Issue
Block a user