forked from HomeAssistant/midea-meiju-codec
v0.0.4
This commit is contained in:
@@ -4,8 +4,6 @@ from homeassistant.const import (
|
||||
CONF_DEVICE_ID,
|
||||
CONF_DEVICE,
|
||||
CONF_ENTITIES,
|
||||
STATE_ON,
|
||||
STATE_OFF
|
||||
)
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
@@ -18,18 +16,19 @@ 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][device_id].get(CONF_DEVICE)
|
||||
manufacturer = hass.data[DOMAIN][DEVICES][device_id].get("manufacturer")
|
||||
rationale = hass.data[DOMAIN][DEVICES][device_id].get("rationale")
|
||||
entities = hass.data[DOMAIN][DEVICES][device_id].get(CONF_ENTITIES).get(Platform.SWITCH)
|
||||
devs = []
|
||||
if entities is not None:
|
||||
for entity_key, config in entities.items():
|
||||
devs.append(MideaSwitchEntity(device, manufacturer, entity_key, config))
|
||||
devs.append(MideaSwitchEntity(device, manufacturer, rationale, entity_key, config))
|
||||
async_add_entities(devs)
|
||||
|
||||
|
||||
class MideaSwitchEntity(MideaBinaryBaseEntity, SwitchEntity):
|
||||
|
||||
def turn_on(self):
|
||||
self._device.set_attribute(attribute=self._entity_key, value=self._binary_rationale[1])
|
||||
self._set_status_on_off(self._entity_key, True)
|
||||
|
||||
def turn_off(self):
|
||||
self._device.set_attribute(attribute=self._entity_key, value=self._binary_rationale[0])
|
||||
self._set_status_on_off(self._entity_key, False)
|
||||
|
Reference in New Issue
Block a user