diff --git a/custom_components/aqara_gateway/core/gateway.py b/custom_components/aqara_gateway/core/gateway.py index 690d1df..6bfb1e1 100755 --- a/custom_components/aqara_gateway/core/gateway.py +++ b/custom_components/aqara_gateway/core/gateway.py @@ -136,7 +136,7 @@ def start(self, hass: HomeAssistant, config_entry: ConfigEntry): else: self.main_task = hass.loop.create_task(self.run()) - async def run(self): + async def async_run(self): """ Main thread loop. """ telnetshell = False if "telnet" not in self.hass.data[DOMAIN]: @@ -154,7 +154,7 @@ async def run(self): devices = self._prepare_gateway(get_devices=True) if isinstance(devices, list): self._gw_topic = "gw/{}/".format(devices[0]['mac'][2:].upper()) - await self.setup_devices(devices) + await self.async_setup_devices(devices) break if telnetshell: @@ -330,7 +330,7 @@ def _get_devices(self, shell): return devices - async def setup_devices(self, devices: list): + async def async_setup_devices(self, devices: list): """Add devices to hass.""" for device in devices: timeout = 300 @@ -478,7 +478,7 @@ def on_disconnect(self, client, userdata, ret): self.hass.data[DOMAIN]["mqtt"].remove(self.host) self.available = False # self.process_gateway_stats() - self.hass.create_task(self.run()) + self.hass.create_task(self.async_run()) def on_message(self, client: Client, userdata, msg: MQTTMessage): # pylint: disable=unused-argument @@ -586,7 +586,7 @@ def _process_devices_info(self, prop, value): 'model_ver': dev['model_ver'], 'status': dev['status'] } - self.hass.create_task(self.setup_devices([device])) + self.hass.create_task(self.async_setup_devices([device])) break def _process_message(self, data: dict): @@ -750,7 +750,7 @@ def _process_message(self, data: dict): device['mac'] = '0x' + device['mac'] device['type'] = 'zigbee' device['init'] = payload - self.hass.create_task(self.setup_devices([device])) + self.hass.create_task(self.async_setup_devices([device])) async def _handle_device_remove(self, payload: dict): """Remove device from Hass. """ diff --git a/custom_components/aqara_gateway/core/utils.py b/custom_components/aqara_gateway/core/utils.py index 2df31e7..df7664b 100755 --- a/custom_components/aqara_gateway/core/utils.py +++ b/custom_components/aqara_gateway/core/utils.py @@ -366,10 +366,13 @@ 'params': [ ['1.10.85', None, 'present_mode', None], ['0.12.85', 'load_power', 'power', 'sensor'], - ['4.1.85', 'power_status', 'light', 'light'], ['14.1.85', 'light_level', 'brightness', None], ['14.2.85', 'colour_temperature', 'color_temp', None], ['14.5.85', 'rgb_color', 'rgb_color', None], + ['4.1.85', 'power_status', 'light', 'light'], + ['14.12.85', 'light_level', 'brightness', None], + ['14.16.85', 'colour_temperature', 'color_temp', None], + ['4.2.85', 'power_status', 'sub light', 'light'], ['14.46.85', None, 'dual_color_temperature_mode', None], ['8.0.2022', None, 'ambilight', None], ['8.0.2150', None, 'dynamic', None], diff --git a/custom_components/aqara_gateway/sensor.py b/custom_components/aqara_gateway/sensor.py index b5cdbae..cad9163 100755 --- a/custom_components/aqara_gateway/sensor.py +++ b/custom_components/aqara_gateway/sensor.py @@ -69,35 +69,35 @@ GATEWAY_PLATFORMS_NO_KEY = ["binary_sensor", "sensor"] -async def async_setup_entry(hass, entry, add_entities): +async def async_setup_entry(hass, entry, async_add_entities): """ setup config entry """ def setup(gateway: Gateway, device: dict, attr: str): if attr == 'gateway': - add_entities([GatewayStats(gateway, device, attr)]) + async_add_entities([GatewayStats(gateway, device, attr)]) elif attr == 'zigbee': - add_entities([ZigbeeStats(gateway, device, attr)]) + async_add_entities([ZigbeeStats(gateway, device, attr)]) elif attr == 'gas density': - add_entities([GatewayGasSensor(gateway, device, attr)]) + async_add_entities([GatewayGasSensor(gateway, device, attr)]) elif attr == 'lock': - add_entities([GatewayLockSensor(gateway, device, attr)]) + async_add_entities([GatewayLockSensor(gateway, device, attr)]) elif attr == 'key_id': - add_entities([GatewayKeyIDSensor(gateway, device, attr)]) + async_add_entities([GatewayKeyIDSensor(gateway, device, attr)]) elif attr == 'lock_event': - add_entities([GatewayLockEventSensor(gateway, device, attr)]) + async_add_entities([GatewayLockEventSensor(gateway, device, attr)]) elif attr in ('hear_rate', 'breath_rate', 'body_movements'): - add_entities([GatewaySleepMonitorSensor(gateway, device, attr)]) + async_add_entities([GatewaySleepMonitorSensor(gateway, device, attr)]) elif attr == 'illuminance': if (device['type'] == 'gateway' and Utils.gateway_illuminance_supported(device['model'])): - add_entities([GatewaySensor(gateway, device, attr)]) + async_add_entities([GatewaySensor(gateway, device, attr)]) elif device['type'] == 'zigbee': - add_entities([GatewaySensor(gateway, device, attr)]) + async_add_entities([GatewaySensor(gateway, device, attr)]) elif attr == 'movements': - add_entities([GatewayMoveSensor(gateway, device, attr)]) + async_add_entities([GatewayMoveSensor(gateway, device, attr)]) elif attr == 'occupancy_region': - add_entities([GatewayOccupancyRegionSensor(gateway, device, attr)]) + async_add_entities([GatewayOccupancyRegionSensor(gateway, device, attr)]) else: - add_entities([GatewaySensor(gateway, device, attr)]) + async_add_entities([GatewaySensor(gateway, device, attr)]) aqara_gateway: Gateway = hass.data[DOMAIN][entry.entry_id] aqara_gateway.add_setup('sensor', setup)