Skip to content

Device support for the xiaomi power strip added.#32

Merged
rytilahti merged 8 commits intorytilahti:masterfrom
syssi:feature/strip
Jul 25, 2017
Merged

Device support for the xiaomi power strip added.#32
rytilahti merged 8 commits intorytilahti:masterfrom
syssi:feature/strip

Conversation

@syssi
Copy link
Copy Markdown
Collaborator

@syssi syssi commented Jul 23, 2017

No description provided.


class StripStatus:
"""Container for status reports from the strip."""
def __init__(self, data: Dict[str, Any]) -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'Dict'
undefined name 'Any'

return StripStatus(dict(zip(properties, values)))

def set_power_mode(self, mode: str):
"""Set mode."""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What kind of modes are accepted?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

"green" (aka eco) and "normal".

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok. Would it be worth expose this as an enum too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Could you provide an example? I'm confused.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

For example something like this:

import enum
class PowerMode(enum.Enum):
    Eco = "green"
    Normal = "normal"

and calling set_power_mode(PowerMode.Eco)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Got it! This is nice. I will update the PRs asap.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Btw, you can then simply use mode.value to get the value on the right hand side insie set_mode(), and other way around when reading it, PowerMode('green') will give you back the PowerMode.Eco :-)


def status(self):
"""Retrieve properties."""
properties = ['power', 'temperature', 'current', 'mode']
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do you have an example response? It would be nice to be added either here or into the Status class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will care about.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Great! (I saw this was added, but the "todo" is still open.

PowerMode class introduced.
return self.data["current"]

@property
def mode(self) -> PowerMode:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'PowerMode'

)
return StripStatus(dict(zip(properties, values)))

def set_power_mode(self, mode: PowerMode):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'PowerMode'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand the complain. :-(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The PowerMode is being used before it has been defined (see my comment in another PR :))

from typing import Any, Dict
import enum

class Strip(Device):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

mirobo/strip.py Outdated
"""Container for status reports from the strip."""

def __init__(self, data: Dict[str, Any]) -> None:
# {'power': 'on', 'temperature': 48.11, 'current': 0.06, 'mode': 'green'}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

@rytilahti
Copy link
Copy Markdown
Owner

Looks good, let's merge it!

@rytilahti rytilahti merged commit a28fab5 into rytilahti:master Jul 25, 2017
@syssi
Copy link
Copy Markdown
Collaborator Author

syssi commented Aug 4, 2017

Known models: 'qmi.powerstrip.v1', 'zimi.powerstrip.v2'

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.

3 participants