Mijia Air Quality Sensor uses `get_value` instead of `get_prop`
valkjsaaa opened this issue · 5 comments
Can we make that configurable?
Here are an example traffic capture:
-> 192.168.144.108 data= {"id":5301,"method":"get_value","params":["pm25","co2e","tvoc","humidity","temperature"]}
<- 192.168.144.162 data= {"result":{"co2e":2648,"humidity":56.100000000000001,"pm25":90,"temperature":24,"tvoc":1.857},"id":5301}
-> 192.168.144.108 data= {"id":5302,"method":"get_value","params":["pm25","co2e","tvoc","humidity","temperature"]}
<- 192.168.144.162 data= {"result":{"co2e":2607,"humidity":56.100000000000001,"pm25":90.299999999999997,"temperature":24,"tvoc":1.8089999999999999},"id":5302}
Sure! I will care about.
I've updated the custom component. Please give it a try!
Thanks for the very quick response, however, for Mijia air quality sensor, the get_value
returns a dictionary instead of a list. So I have to change the code in sensor.py
to the something like this:
try:
# A single request is limited to 16 properties. Therefore the
# properties are divided into multiple requests
_props = self._properties.copy()
values = []
while _props:
result_dict = await self.hass.async_add_job(
self._device.send, "get_value", _props[:15]
)
values.extend(
[result_dict[name] for name in _props[:15]]
)
_props[:] = _props[15:]
Also I just noticed that you have already added this sensor to python-miio
and home-assistant
, so I'm not sure it's worth it to add this feature here.
BTW, it seems the home-assistant implementation of this sensor have some problem, and I have created a simple fix. Please take a look :)
Good job! I will merge your fix ASAP!
Are you able to provide a generic solution of your code change here? Try to identify the structure of the response and rewrite it if necessary.