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

Abstract device model exteded by model name (identifier) #64

Merged
merged 2 commits into from
Sep 6, 2017

Conversation

syssi
Copy link
Collaborator

@syssi syssi commented Sep 6, 2017

No description provided.

mirobo/device.py Outdated
@@ -2,7 +2,7 @@
import datetime
import socket
import logging
from typing import Any, List
from typing import Any, List, Optional

Choose a reason for hiding this comment

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

'typing.List' imported but unused

Copy link
Collaborator Author

@syssi syssi Sep 6, 2017

Choose a reason for hiding this comment

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

It's used as annotation. This is fine.

Copy link
Owner

Choose a reason for hiding this comment

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

Indeed, I added a noqa for those cases for now.

@coveralls
Copy link

coveralls commented Sep 6, 2017

Coverage Status

Coverage increased (+0.1%) to 32.877% when pulling 75a1899 on syssi:feature/retrieve-device-model into b374872 on rytilahti:master.

mirobo/device.py Outdated
@@ -184,6 +190,9 @@ def raw_command(self, cmd, params):
def info(self):
return DeviceInfo(self.send("miIO.info", []))

def model(self):
return self.info().model
Copy link
Owner

Choose a reason for hiding this comment

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

Although I think it's fine to expose the model information directly in DeviceInfo, I'm not sure if the Device interface should be extended to expose this too. What is the usecase you have in your mind and would it be too bad to access the model directly there on the call-site?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to provide the model of the device as sensor attribute at home assistant. It's good to know as long there is no discovery process and the user has to decide which component to use. Especially if various generations of a device exists I would like to handle the firmware differences properly.

Copy link
Owner

Choose a reason for hiding this comment

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

Makes sense, but would it be too bad to fetch info only once and use the DeviceInfo to get extract the information out from it, making the fetch explicit and avoid doing multiple I/O calls when accessing other information from the object.

mirobo/device.py Outdated
@@ -25,14 +25,20 @@ def __repr__(self):
self.data["token"])

@property
def netif(self):
def netif(self) -> str:
Copy link
Owner

Choose a reason for hiding this comment

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

IIRC these are not strings but rather dicts, maybe it's a good idea to add an example output into the class' docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My fault. I wil add a proper docstring for the future.

Copy link
Owner

Choose a reason for hiding this comment

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

Not a problem. Looks like I lost my connectivity to my raspberry pi running as a controller, so I can't do much testing on this for now. If you can, could you please add the output of the info() to the doctstring of DeviceInfo class (that will also help when creating unit tests at some point).

@syssi syssi force-pushed the feature/retrieve-device-model branch from 0faacbe to fd715bd Compare September 6, 2017 17:44
@rytilahti
Copy link
Owner

Mmh, looks like coveralls got stuck for some reason. Anyway, this all looks fine so I'm merging it.

@rytilahti rytilahti merged commit 3cd4b30 into rytilahti:master Sep 6, 2017
@coveralls
Copy link

coveralls commented Sep 6, 2017

Coverage Status

Coverage increased (+0.02%) to 32.894% when pulling fd715bd on syssi:feature/retrieve-device-model into 9424964 on rytilahti:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants