Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the cgllc.airmonitor.b1 #562

Merged
merged 16 commits into from
Oct 20, 2019
Merged

Add support for the cgllc.airmonitor.b1 #562

merged 16 commits into from
Oct 20, 2019

Conversation

fwestenberg
Copy link
Contributor

Added support for cgllc.airmonitor.b1

image

Added support for cgllc.airmonitor.b1
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Oct 13, 2019

Coverage Status

Coverage decreased (-0.2%) to 72.013% when pulling eb77c8c on fwestenberg:patch-1 into 849bc9e on rytilahti:master.

miio/airqualitymonitor.py Outdated Show resolved Hide resolved
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover)

if model == None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add I/O at the constructor. The correct model should be passed to the constructor if needed.

miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Show resolved Hide resolved
@syssi syssi changed the title Update airqualitymonitor.py Improve the cgllc.airmonitor.b1 support Oct 14, 2019
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
@@ -206,11 +241,12 @@ def __init__(

if model in AVAILABLE_PROPERTIES:
self.model = model
else:
elif model is not None:
self.model = MODEL_AIRQUALITYMONITOR_V1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a model is provided, but not in available_properties fallback is still there.

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the first glance this looks good to me.

miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
miio/airqualitymonitor.py Outdated Show resolved Hide resolved
@fwestenberg
Copy link
Contributor Author

Thanks for your suggestions! Please let me know if anything else should be changed.

self._model = info.model
self._mac_address = info.mac_address
self._firmware_version = info.firmware_version
self._hardware_version = info.hardware_version
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you planning to use these? To me it looks like they are not used at all, so it'd be better simply to remove the last three lines, no?

If it's for homeassistant integration, it should simply query the info itself and parse the information out from it (instead of accessing these now-private variables) :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is instead for the HA integration. But I don't like the idea of querying the info again. Also I don't see any trouble in saving the info on device-level. So now the remaining question to me is: where to store them? I suppose all of the Xiaomi Air Quality devices have the same response here?

Copy link
Contributor Author

@fwestenberg fwestenberg Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating the following in the AirQualityMonitor class (for mac_address, model, firmware_version and hardware_version):

@property
def mac_address(self) -> Optional[int]:
"""Return mac address."""
return self._mac_address

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking if it would make simply sense to extend Device's info() to cache the result (and add a kwarg refresh if there's a need to force re-fetching), as I assume the information returned is quite static (see https://github.com/rytilahti/python-miio/blob/master/miio/device.py#L33).

But that should be done in a separate PR, for the time being I would do the caching downstream (as you already do in the homeassistant PR) and we can think about adapting the behavior of info() (https://github.com/rytilahti/python-miio/blob/master/miio/device.py#L348) to cache the results for some time period or until explicitly asked for a refresh.

@syssi do you have an opinion on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First it started with getting the device model, which is needed in case of te B1 to simply get te status. That's why I added the info( ) call in the first place to the init, and then moved it to the status method. Here the info( ) is only called once, when model is None.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I got that, but what I'm trying to say is that those internal (info) variables should not be exposed like this only for a single device type. There is already DeviceInfo container holding this information, so the homeassistant part should simply call info (once) and save those details for its own use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reversed some changes (model, firmware etc). All should be fine now (I hope).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! Let's get it merged! 🎉

miio/tests/test_airqualitymonitor.py Outdated Show resolved Hide resolved
miio/tests/test_airqualitymonitor.py Outdated Show resolved Hide resolved
@rytilahti rytilahti changed the title Improve the cgllc.airmonitor.b1 support Add support for the cgllc.airmonitor.b1 Oct 20, 2019
@rytilahti rytilahti merged commit cd99dd3 into rytilahti:master Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants