Add platform specific DPS to requests
This commit is contained in:
committed by
rospogrigio
parent
8cc978a04d
commit
8456c6039c
@@ -65,4 +65,6 @@ class LocaltuyaBinarySensor(LocalTuyaEntity, BinarySensorEntity):
|
||||
)
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaBinarySensor)
|
||||
async_setup_entry = partial(
|
||||
async_setup_entry, DOMAIN, LocaltuyaBinarySensor, flow_schema
|
||||
)
|
||||
|
@@ -40,7 +40,7 @@ def prepare_setup_entities(hass, config_entry, platform):
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
domain, entity_class, hass, config_entry, async_add_entities
|
||||
domain, entity_class, flow_schema, hass, config_entry, async_add_entities
|
||||
):
|
||||
"""Set up a Tuya platform based on a config entry.
|
||||
|
||||
@@ -53,8 +53,15 @@ async def async_setup_entry(
|
||||
if not entities_to_setup:
|
||||
return
|
||||
|
||||
dps_config_fields = list(get_dps_for_platform(flow_schema))
|
||||
|
||||
entities = []
|
||||
for device_config in entities_to_setup:
|
||||
# Add DPS used by this platform to the request list
|
||||
for dp_conf in dps_config_fields:
|
||||
if dp_conf in device_config:
|
||||
tuyainterface._interface.add_dps_to_request(device_config[dp_conf])
|
||||
|
||||
entities.append(
|
||||
entity_class(
|
||||
tuyainterface,
|
||||
@@ -66,6 +73,13 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
def get_dps_for_platform(flow_schema):
|
||||
"""Return config keys for all platform keys that depends on a datapoint."""
|
||||
for key, value in flow_schema(None).items():
|
||||
if hasattr(value, "container") and value.container is None:
|
||||
yield key.schema
|
||||
|
||||
|
||||
def get_entity_config(config_entry, dps_id):
|
||||
"""Return entity config for a given DPS id."""
|
||||
for entity in config_entry.data[CONF_ENTITIES]:
|
||||
|
@@ -165,4 +165,4 @@ class LocaltuyaCover(LocalTuyaEntity, CoverEntity):
|
||||
self._current_cover_position = 50
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaCover)
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaCover, flow_schema)
|
||||
|
@@ -110,4 +110,4 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity):
|
||||
self._oscillating = self._status["dps"]["8"]
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaFan)
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaFan, flow_schema)
|
||||
|
@@ -121,4 +121,4 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
|
||||
self._color_temp = self.dps(DPS_INDEX_COLOURTEMP)
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaLight)
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaLight, flow_schema)
|
||||
|
@@ -69,4 +69,4 @@ class LocaltuyaSensor(LocalTuyaEntity):
|
||||
self._state = state
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaSensor)
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaSensor, flow_schema)
|
||||
|
@@ -78,4 +78,4 @@ class LocaltuyaSwitch(LocalTuyaEntity, SwitchEntity):
|
||||
self._state = self.dps(self._dps_id)
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaSwitch)
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaSwitch, flow_schema)
|
||||
|
Reference in New Issue
Block a user