Skip to content

Commit cdb489c

Browse files
author
niceboy
committed
Fix adding sensors entities which did not use async_add_entities
1 parent a2ff161 commit cdb489c

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

custom_components/aqara_gateway/core/gateway.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def start(self, hass: HomeAssistant, config_entry: ConfigEntry):
136136
else:
137137
self.main_task = hass.loop.create_task(self.run())
138138

139-
async def run(self):
139+
async def async_run(self):
140140
""" Main thread loop. """
141141
telnetshell = False
142142
if "telnet" not in self.hass.data[DOMAIN]:
@@ -154,7 +154,7 @@ async def run(self):
154154
devices = self._prepare_gateway(get_devices=True)
155155
if isinstance(devices, list):
156156
self._gw_topic = "gw/{}/".format(devices[0]['mac'][2:].upper())
157-
await self.setup_devices(devices)
157+
await self.async_setup_devices(devices)
158158
break
159159

160160
if telnetshell:
@@ -330,7 +330,7 @@ def _get_devices(self, shell):
330330

331331
return devices
332332

333-
async def setup_devices(self, devices: list):
333+
async def async_setup_devices(self, devices: list):
334334
"""Add devices to hass."""
335335
for device in devices:
336336
timeout = 300
@@ -478,7 +478,7 @@ def on_disconnect(self, client, userdata, ret):
478478
self.hass.data[DOMAIN]["mqtt"].remove(self.host)
479479
self.available = False
480480
# self.process_gateway_stats()
481-
self.hass.create_task(self.run())
481+
self.hass.create_task(self.async_run())
482482

483483
def on_message(self, client: Client, userdata, msg: MQTTMessage):
484484
# pylint: disable=unused-argument
@@ -586,7 +586,7 @@ def _process_devices_info(self, prop, value):
586586
'model_ver': dev['model_ver'],
587587
'status': dev['status']
588588
}
589-
self.hass.create_task(self.setup_devices([device]))
589+
self.hass.create_task(self.async_setup_devices([device]))
590590
break
591591

592592
def _process_message(self, data: dict):
@@ -750,7 +750,7 @@ def _process_message(self, data: dict):
750750
device['mac'] = '0x' + device['mac']
751751
device['type'] = 'zigbee'
752752
device['init'] = payload
753-
self.hass.create_task(self.setup_devices([device]))
753+
self.hass.create_task(self.async_setup_devices([device]))
754754

755755
async def _handle_device_remove(self, payload: dict):
756756
"""Remove device from Hass. """

custom_components/aqara_gateway/core/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,13 @@
366366
'params': [
367367
['1.10.85', None, 'present_mode', None],
368368
['0.12.85', 'load_power', 'power', 'sensor'],
369-
['4.1.85', 'power_status', 'light', 'light'],
370369
['14.1.85', 'light_level', 'brightness', None],
371370
['14.2.85', 'colour_temperature', 'color_temp', None],
372371
['14.5.85', 'rgb_color', 'rgb_color', None],
372+
['4.1.85', 'power_status', 'light', 'light'],
373+
['14.12.85', 'light_level', 'brightness', None],
374+
['14.16.85', 'colour_temperature', 'color_temp', None],
375+
['4.2.85', 'power_status', 'sub light', 'light'],
373376
['14.46.85', None, 'dual_color_temperature_mode', None],
374377
['8.0.2022', None, 'ambilight', None],
375378
['8.0.2150', None, 'dynamic', None],

custom_components/aqara_gateway/sensor.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,35 @@
6969
GATEWAY_PLATFORMS_NO_KEY = ["binary_sensor", "sensor"]
7070

7171

72-
async def async_setup_entry(hass, entry, add_entities):
72+
async def async_setup_entry(hass, entry, async_add_entities):
7373
""" setup config entry """
7474
def setup(gateway: Gateway, device: dict, attr: str):
7575
if attr == 'gateway':
76-
add_entities([GatewayStats(gateway, device, attr)])
76+
async_add_entities([GatewayStats(gateway, device, attr)])
7777
elif attr == 'zigbee':
78-
add_entities([ZigbeeStats(gateway, device, attr)])
78+
async_add_entities([ZigbeeStats(gateway, device, attr)])
7979
elif attr == 'gas density':
80-
add_entities([GatewayGasSensor(gateway, device, attr)])
80+
async_add_entities([GatewayGasSensor(gateway, device, attr)])
8181
elif attr == 'lock':
82-
add_entities([GatewayLockSensor(gateway, device, attr)])
82+
async_add_entities([GatewayLockSensor(gateway, device, attr)])
8383
elif attr == 'key_id':
84-
add_entities([GatewayKeyIDSensor(gateway, device, attr)])
84+
async_add_entities([GatewayKeyIDSensor(gateway, device, attr)])
8585
elif attr == 'lock_event':
86-
add_entities([GatewayLockEventSensor(gateway, device, attr)])
86+
async_add_entities([GatewayLockEventSensor(gateway, device, attr)])
8787
elif attr in ('hear_rate', 'breath_rate', 'body_movements'):
88-
add_entities([GatewaySleepMonitorSensor(gateway, device, attr)])
88+
async_add_entities([GatewaySleepMonitorSensor(gateway, device, attr)])
8989
elif attr == 'illuminance':
9090
if (device['type'] == 'gateway' and
9191
Utils.gateway_illuminance_supported(device['model'])):
92-
add_entities([GatewaySensor(gateway, device, attr)])
92+
async_add_entities([GatewaySensor(gateway, device, attr)])
9393
elif device['type'] == 'zigbee':
94-
add_entities([GatewaySensor(gateway, device, attr)])
94+
async_add_entities([GatewaySensor(gateway, device, attr)])
9595
elif attr == 'movements':
96-
add_entities([GatewayMoveSensor(gateway, device, attr)])
96+
async_add_entities([GatewayMoveSensor(gateway, device, attr)])
9797
elif attr == 'occupancy_region':
98-
add_entities([GatewayOccupancyRegionSensor(gateway, device, attr)])
98+
async_add_entities([GatewayOccupancyRegionSensor(gateway, device, attr)])
9999
else:
100-
add_entities([GatewaySensor(gateway, device, attr)])
100+
async_add_entities([GatewaySensor(gateway, device, attr)])
101101

102102
aqara_gateway: Gateway = hass.data[DOMAIN][entry.entry_id]
103103
aqara_gateway.add_setup('sensor', setup)

0 commit comments

Comments
 (0)