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

Air purifier: defaultdict used for safety and transparency #49

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions mirobo/airpurifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
from .device import Device
from typing import Any, Dict
import enum

_LOGGER = logging.getLogger(__name__)


class OperationMode(enum.Enum):
Auto = 'auto'
Expand All @@ -22,7 +25,6 @@ class AirPurifier(Device):
def status(self):
"""Retrieve properties."""

# A few more properties:
properties = ['power', 'aqi', 'humidity', 'temp_dec',
'mode', 'led', 'led_b', 'buzzer', 'child_lock',
'bright', 'favorite_level', 'filter1_life',
Expand All @@ -32,7 +34,16 @@ def status(self):
"get_prop",
properties
)
return AirPurifierStatus(dict(zip(properties, values)))

properties_count = len(properties)
values_count = len(values)
if properties_count != values_count:
_LOGGER.debug(
"Count (%s) of requested properties does not match the "
"count (%s) of received values.",
properties_count, values_count)

return CeilStatus(defaultdict(lambda: None, zip(properties, values)))

Choose a reason for hiding this comment

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

undefined name 'CeilStatus'
undefined name 'defaultdict'


def on(self):
"""Power on."""
Expand Down Expand Up @@ -98,7 +109,7 @@ def __init__(self, data: Dict[str, Any]) -> None:
'act_det': null, 'f1_hour_used': 680 ]

use_time and motor1_speed is missing because a request is limitted
to 16 properties.
to 16 properties. We request 15 properties at the moment.
"""

self.data = data
Expand Down