Skip to content

Commit

Permalink
Add timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
MarBra committed May 23, 2020
1 parent b4a961b commit 450429c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions homeassistant/components/xiaomi_miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
ATTR_STATUS = "status"
ATTR_ZONE_ARRAY = "zone"
ATTR_ZONE_REPEATER = "repeats"
ATTR_TIMEZONE = "timezone"
ATTR_TIMERS = "timers"

VACUUM_SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids})
Expand Down Expand Up @@ -248,6 +249,7 @@ def __init__(self, name, vacuum):
self._fan_speeds = None
self._fan_speeds_reverse = None

self.timezone = None
self._timers = None

@property
Expand Down Expand Up @@ -347,6 +349,9 @@ def device_state_attributes(self):
if self.vacuum_state.got_error:
attrs[ATTR_ERROR] = self.vacuum_state.error

if self.timezone:
attrs[ATTR_TIMEZONE] = self.timezone

if self.timers:
attrs[ATTR_TIMERS] = self.timers
return attrs
Expand Down Expand Up @@ -475,6 +480,7 @@ def update(self):
self.last_clean = self._vacuum.last_clean_details()
self.dnd_state = self._vacuum.dnd_status()

self.timezone = self._vacuum.timezone()
self._timers = self._vacuum.timer()

self._available = True
Expand Down
7 changes: 7 additions & 0 deletions tests/components/xiaomi_miio/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ATTR_MAIN_BRUSH_LEFT,
ATTR_SIDE_BRUSH_LEFT,
ATTR_TIMERS,
ATTR_TIMEZONE,
CONF_HOST,
CONF_NAME,
CONF_TOKEN,
Expand Down Expand Up @@ -105,6 +106,8 @@ def mirobo_is_got_error_fixture():

mock_vacuum.timer.return_value = [mock_timer_1, mock_timer_2]

mock_vacuum.timezone.return_value = "Europe/Berlin"

with mock.patch(
"homeassistant.components.xiaomi_miio.vacuum.Vacuum"
) as mock_vaccum_cls:
Expand Down Expand Up @@ -181,6 +184,8 @@ def mirobo_is_on_fixture():

mock_vacuum.timer.return_value = [mock_timer_1, mock_timer_2]

mock_vacuum.timezone.return_value = "Europe/Berlin"

with mock.patch(
"homeassistant.components.xiaomi_miio.vacuum.Vacuum"
) as mock_vaccum_cls:
Expand Down Expand Up @@ -266,6 +271,7 @@ async def test_xiaomi_vacuum_services(hass, caplog, mock_mirobo_is_got_error):
{"enabled": True, "time": time(hour=9, minute=0)},
{"enabled": False, "time": time(hour=11, minute=0)},
]
assert state.attributes.get(ATTR_TIMEZONE) == "Europe/Berlin"

# Call services
await hass.services.async_call(
Expand Down Expand Up @@ -370,6 +376,7 @@ async def test_xiaomi_specific_services(hass, caplog, mock_mirobo_is_on):
{"enabled": True, "time": time(hour=9, minute=0)},
{"enabled": False, "time": time(hour=11, minute=0)},
]
assert state.attributes.get(ATTR_TIMEZONE) == "Europe/Berlin"

# Xiaomi vacuum specific services:
await hass.services.async_call(
Expand Down

0 comments on commit 450429c

Please sign in to comment.