From 512348770538fd44f5b15389d9c6bbd1f516484c Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Thu, 25 Jan 2018 11:31:38 -0500 Subject: [PATCH] Update python-wink version and multiple wink fixes/updates. (#11833) --- homeassistant/components/binary_sensor/wink.py | 7 +++++++ homeassistant/components/climate/wink.py | 18 ++++++++++++++++++ homeassistant/components/cover/wink.py | 17 ++++++++++------- homeassistant/components/wink/__init__.py | 6 +++++- homeassistant/components/wink/services.yaml | 2 +- requirements_all.txt | 2 +- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/binary_sensor/wink.py b/homeassistant/components/binary_sensor/wink.py index 55f6af3719e..575507cd047 100644 --- a/homeassistant/components/binary_sensor/wink.py +++ b/homeassistant/components/binary_sensor/wink.py @@ -143,6 +143,13 @@ class WinkHub(WinkBinarySensorDevice): _attributes['update_needed'] = self.wink.update_needed() _attributes['firmware_version'] = self.wink.firmware_version() _attributes['pairing_mode'] = self.wink.pairing_mode() + _kidde_code = self.wink.kidde_radio_code() + if _kidde_code is not None: + # The service call to set the Kidde code + # takes a string of 1s and 0s so it makes + # sense to display it to the user that way + _formatted_kidde_code = "{:b}".format(_kidde_code).zfill(8) + _attributes['kidde_radio_code'] = _formatted_kidde_code return _attributes diff --git a/homeassistant/components/climate/wink.py b/homeassistant/components/climate/wink.py index 2c287fc6846..50374a32807 100644 --- a/homeassistant/components/climate/wink.py +++ b/homeassistant/components/climate/wink.py @@ -30,6 +30,8 @@ ATTR_SCHEDULE_ENABLED = 'schedule_enabled' ATTR_SMART_TEMPERATURE = 'smart_temperature' ATTR_TOTAL_CONSUMPTION = 'total_consumption' ATTR_VACATION_MODE = 'vacation_mode' +ATTR_HEAT_ON = 'heat_on' +ATTR_COOL_ON = 'cool_on' DEPENDENCIES = ['wink'] @@ -131,6 +133,12 @@ class WinkThermostat(WinkDevice, ClimateDevice): if self.eco_target: data[ATTR_ECO_TARGET] = self.eco_target + if self.heat_on: + data[ATTR_HEAT_ON] = self.heat_on + + if self.cool_on: + data[ATTR_COOL_ON] = self.cool_on + current_humidity = self.current_humidity if current_humidity is not None: data[ATTR_CURRENT_HUMIDITY] = current_humidity @@ -174,6 +182,16 @@ class WinkThermostat(WinkDevice, ClimateDevice): """Return status of if the thermostat has detected occupancy.""" return self.wink.occupied() + @property + def heat_on(self): + """Return whether or not the heat is actually heating.""" + return self.wink.heat_on() + + @property + def cool_on(self): + """Return whether or not the heat is actually heating.""" + return self.wink.heat_on() + @property def current_operation(self): """Return current operation ie. heat, cool, idle.""" diff --git a/homeassistant/components/cover/wink.py b/homeassistant/components/cover/wink.py index b3276bdf8cc..35f14e80b5b 100644 --- a/homeassistant/components/cover/wink.py +++ b/homeassistant/components/cover/wink.py @@ -6,8 +6,8 @@ https://home-assistant.io/components/cover.wink/ """ import asyncio -from homeassistant.components.cover import CoverDevice -from homeassistant.components.wink import DOMAIN, WinkDevice +from homeassistant.components.cover import CoverDevice, STATE_UNKNOWN +from homeassistant.components.wink import WinkDevice, DOMAIN DEPENDENCIES = ['wink'] @@ -35,21 +35,24 @@ class WinkCoverDevice(WinkDevice, CoverDevice): self.hass.data[DOMAIN]['entities']['cover'].append(self) def close_cover(self, **kwargs): - """Close the shade.""" + """Close the cover.""" self.wink.set_state(0) def open_cover(self, **kwargs): - """Open the shade.""" + """Open the cover.""" self.wink.set_state(1) def set_cover_position(self, position, **kwargs): - """Move the roller shutter to a specific position.""" + """Move the cover shutter to a specific position.""" self.wink.set_state(float(position)/100) @property def current_cover_position(self): - """Return the current position of roller shutter.""" - return int(self.wink.state()*100) + """Return the current position of cover shutter.""" + if self.wink.state() is not None: + return int(self.wink.state()*100) + else: + return STATE_UNKNOWN @property def is_closed(self): diff --git a/homeassistant/components/wink/__init__.py b/homeassistant/components/wink/__init__.py index 476f089b592..78f3042aefb 100644 --- a/homeassistant/components/wink/__init__.py +++ b/homeassistant/components/wink/__init__.py @@ -26,7 +26,7 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.event import track_time_interval from homeassistant.util.json import load_json, save_json -REQUIREMENTS = ['python-wink==1.7.1', 'pubnubsub-handler==1.0.2'] +REQUIREMENTS = ['python-wink==1.7.3', 'pubnubsub-handler==1.0.2'] _LOGGER = logging.getLogger(__name__) @@ -357,6 +357,10 @@ def setup(hass, config): hass.bus.listen(EVENT_HOMEASSISTANT_STOP, save_credentials) + # Save the users potentially updated oauth credentials at a regular + # interval to prevent them from being expired after a HA reboot. + track_time_interval(hass, save_credentials, timedelta(minutes=60)) + def force_update(call): """Force all devices to poll the Wink API.""" _LOGGER.info("Refreshing Wink states from API") diff --git a/homeassistant/components/wink/services.yaml b/homeassistant/components/wink/services.yaml index 5190b75d574..1dc4ecf959b 100644 --- a/homeassistant/components/wink/services.yaml +++ b/homeassistant/components/wink/services.yaml @@ -10,7 +10,7 @@ pair_new_device: description: One of ["zigbee", "zwave", "zwave_exclusion", "zwave_network_rediscovery", "lutron", "bluetooth", "kidde"]. example: 'zigbee' kidde_radio_code: - description: 'A string of 8 1s and 0s one for each dip switch on the kidde device left --> right = 1 --> 8' + description: 'A string of 8 1s and 0s one for each dip switch on the kidde device left --> right = 1 --> 8. Down = 1 and Up = 0' example: '10101010' rename_wink_device: diff --git a/requirements_all.txt b/requirements_all.txt index 09f83cda77c..c708548365a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -948,7 +948,7 @@ python-velbus==2.0.11 python-vlc==1.1.2 # homeassistant.components.wink -python-wink==1.7.1 +python-wink==1.7.3 # homeassistant.components.sensor.swiss_public_transport python_opendata_transport==0.0.3