Sensor updates (#3410)

This commit is contained in:
William Scanlon 2016-09-20 03:05:54 -04:00 committed by Paulus Schoutsen
parent 68835c4b4b
commit 43c395232a
10 changed files with 45 additions and 143 deletions

View File

@ -1,19 +1,17 @@
""" """
Support for Wink sensors. Support for Wink binary sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
at https://home-assistant.io/components/sensor.wink/ at https://home-assistant.io/components/binary_sensor.wink/
""" """
import logging
import json import json
from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.sensor.wink import WinkDevice from homeassistant.components.sensor.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.loader import get_component from homeassistant.loader import get_component
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
# These are the available sensors mapped to binary_sensor class # These are the available sensors mapped to binary_sensor class
SENSOR_TYPES = { SENSOR_TYPES = {
@ -21,7 +19,8 @@ SENSOR_TYPES = {
"brightness": "light", "brightness": "light",
"vibration": "vibration", "vibration": "vibration",
"loudness": "sound", "loudness": "sound",
"liquid_detected": "moisture" "liquid_detected": "moisture",
"motion": "motion"
} }
@ -29,17 +28,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink binary sensor platform.""" """Setup the Wink binary sensor platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
for sensor in pywink.get_sensors(): for sensor in pywink.get_sensors():
if sensor.capability() in SENSOR_TYPES: if sensor.capability() in SENSOR_TYPES:
add_devices([WinkBinarySensorDevice(sensor)]) add_devices([WinkBinarySensorDevice(sensor)])
@ -77,6 +65,8 @@ class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity):
return self.wink.brightness_boolean() return self.wink.brightness_boolean()
elif self.capability == "liquid_detected": elif self.capability == "liquid_detected":
return self.wink.liquid_boolean() return self.wink.liquid_boolean()
elif self.capability == "motion":
return self.wink.motion_boolean()
else: else:
return self.wink.state() return self.wink.state()

View File

@ -4,48 +4,30 @@ Support for Wink Covers.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.wink/ https://home-assistant.io/components/cover.wink/
""" """
import logging
from homeassistant.components.cover import CoverDevice from homeassistant.components.cover import CoverDevice
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink cover platform.""" """Setup the Wink cover platform."""
import pywink import pywink
if discovery_info is None: add_devices(WinkCoverDevice(shade) for shade, door in
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkCoverDevice(shade) for shade in
pywink.get_shades()) pywink.get_shades())
add_devices(WinkCoverDevice(door) for door in add_devices(WinkCoverDevice(door) for door in
pywink.get_garage_doors()) pywink.get_garage_doors())
class WinkCoverDevice(WinkDevice, CoverDevice): class WinkCoverDevice(WinkDevice, CoverDevice):
"""Representation of a Wink covers.""" """Representation of a Wink cover device."""
def __init__(self, wink): def __init__(self, wink):
"""Initialize the cover.""" """Initialize the cover."""
WinkDevice.__init__(self, wink) WinkDevice.__init__(self, wink)
@property
def should_poll(self):
"""Wink Shades don't track their position."""
return False
def close_cover(self): def close_cover(self):
"""Close the shade.""" """Close the shade."""
self.wink.set_state(0) self.wink.set_state(0)

View File

@ -4,30 +4,17 @@ Support for Wink garage doors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/garage_door.wink/ https://home-assistant.io/components/garage_door.wink/
""" """
import logging
from homeassistant.components.garage_door import GarageDoorDevice from homeassistant.components.garage_door import GarageDoorDevice
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink garage door platform.""" """Setup the Wink garage door platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkGarageDoorDevice(door) for door in add_devices(WinkGarageDoorDevice(door) for door in
pywink.get_garage_doors()) pywink.get_garage_doors())

View File

@ -4,19 +4,17 @@ Support for Wink lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.wink/ https://home-assistant.io/components/light.wink/
""" """
import logging
import colorsys import colorsys
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light) SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light)
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.util import color as color_util from homeassistant.util import color as color_util
from homeassistant.util.color import \ from homeassistant.util.color import \
color_temperature_mired_to_kelvin as mired_to_kelvin color_temperature_mired_to_kelvin as mired_to_kelvin
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR
@ -25,17 +23,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink lights.""" """Setup the Wink lights."""
import pywink import pywink
token = config.get(CONF_ACCESS_TOKEN)
if not pywink.is_token_set() and token is None:
logging.getLogger(__name__).error(
"Missing wink access_token - "
"get one at https://winkbearertoken.appspot.com/")
return
elif token is not None:
pywink.set_bearer_token(token)
add_devices(WinkLight(light) for light in pywink.get_bulbs()) add_devices(WinkLight(light) for light in pywink.get_bulbs())

View File

@ -4,30 +4,17 @@ Support for Wink locks.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/lock.wink/ https://home-assistant.io/components/lock.wink/
""" """
import logging
from homeassistant.components.lock import LockDevice from homeassistant.components.lock import LockDevice
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink platform.""" """Setup the Wink platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkLockDevice(lock) for lock in pywink.get_locks()) add_devices(WinkLockDevice(lock) for lock in pywink.get_locks())

View File

@ -4,30 +4,17 @@ Support for Wink Shades.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/rollershutter.wink/ https://home-assistant.io/components/rollershutter.wink/
""" """
import logging
from homeassistant.components.rollershutter import RollershutterDevice from homeassistant.components.rollershutter import RollershutterDevice
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink rollershutter platform.""" """Setup the Wink rollershutter platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkRollershutterDevice(shade) for shade in add_devices(WinkRollershutterDevice(shade) for shade in
pywink.get_shades()) pywink.get_shades())

View File

@ -6,38 +6,35 @@ at https://home-assistant.io/components/sensor.wink/
""" """
import logging import logging
from homeassistant.const import (CONF_ACCESS_TOKEN, STATE_CLOSED, from homeassistant.const import (STATE_CLOSED,
STATE_OPEN, TEMP_CELSIUS) STATE_OPEN, TEMP_CELSIUS)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.loader import get_component from homeassistant.loader import get_component
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
SENSOR_TYPES = ['temperature', 'humidity'] SENSOR_TYPES = ['temperature', 'humidity', 'balance']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink platform.""" """Setup the Wink platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
for sensor in pywink.get_sensors(): for sensor in pywink.get_sensors():
if sensor.capability() in SENSOR_TYPES: if sensor.capability() in SENSOR_TYPES:
add_devices([WinkSensorDevice(sensor)]) add_devices([WinkSensorDevice(sensor)])
add_devices(WinkEggMinder(eggtray) for eggtray in pywink.get_eggtrays()) add_devices(WinkEggMinder(eggtray) for eggtray in pywink.get_eggtrays())
for piggy_bank in pywink.get_piggy_banks():
try:
if piggy_bank.capability() in SENSOR_TYPES:
add_devices([WinkSensorDevice(piggy_bank)])
except AttributeError:
logging.getLogger(__name__).error(
"Device is not a sensor.")
class WinkSensorDevice(WinkDevice, Entity): class WinkSensorDevice(WinkDevice, Entity):
"""Representation of a Wink sensor.""" """Representation of a Wink sensor."""
@ -59,9 +56,23 @@ class WinkSensorDevice(WinkDevice, Entity):
return round(self.wink.humidity_percentage()) return round(self.wink.humidity_percentage())
elif self.capability == "temperature": elif self.capability == "temperature":
return round(self.wink.temperature_float(), 1) return round(self.wink.temperature_float(), 1)
elif self.capability == "balance":
return round(self.wink.balance() / 100, 2)
else: else:
return STATE_OPEN if self.is_open else STATE_CLOSED return STATE_OPEN if self.is_open else STATE_CLOSED
@property
def available(self):
"""
True if connection == True.
Always return true for Wink porkfolio due to
bug in API.
"""
if self.capability == "balance":
return True
return self.wink.available
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""

View File

@ -4,30 +4,17 @@ Support for Wink switches.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.wink/ https://home-assistant.io/components/switch.wink/
""" """
import logging
from homeassistant.components.wink import WinkDevice from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity import ToggleEntity
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] DEPENDENCIES = ['wink']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Wink platform.""" """Setup the Wink platform."""
import pywink import pywink
if discovery_info is None:
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token. "
"Get one at https://winkbearertoken.appspot.com/")
return
pywink.set_bearer_token(token)
add_devices(WinkToggleDevice(switch) for switch in pywink.get_switches()) add_devices(WinkToggleDevice(switch) for switch in pywink.get_switches())
add_devices(WinkToggleDevice(switch) for switch in add_devices(WinkToggleDevice(switch) for switch in
pywink.get_powerstrip_outlets()) pywink.get_powerstrip_outlets())
@ -35,7 +22,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WinkToggleDevice(WinkDevice, ToggleEntity): class WinkToggleDevice(WinkDevice, ToggleEntity):
"""Represents a Wink toggle (switch) device.""" """Representation of a Wink toggle device."""
def __init__(self, wink): def __init__(self, wink):
"""Initialize the Wink device.""" """Initialize the Wink device."""

View File

@ -14,7 +14,7 @@ from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2'] REQUIREMENTS = ['python-wink==0.7.15', 'pubnub==3.8.2']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -26,7 +26,7 @@ SUBSCRIPTION_HANDLER = None
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({ DOMAIN: vol.Schema({
vol.Optional(CONF_ACCESS_TOKEN): cv.string, vol.Required(CONF_ACCESS_TOKEN): cv.string,
}), }),
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
@ -41,7 +41,7 @@ def setup(hass, config):
'N/A', pywink.get_subscription_key(), ssl_on=True) 'N/A', pywink.get_subscription_key(), ssl_on=True)
SUBSCRIPTION_HANDLER.set_heartbeat(120) SUBSCRIPTION_HANDLER.set_heartbeat(120)
# Load components for the devices in the Wink that we support # Load components for the devices in Wink that we support
for component_name, func_exists in ( for component_name, func_exists in (
('light', pywink.get_bulbs), ('light', pywink.get_bulbs),
('switch', lambda: pywink.get_switches or pywink.get_sirens or ('switch', lambda: pywink.get_switches or pywink.get_sirens or

View File

@ -285,14 +285,6 @@ proliphix==0.3.1
psutil==4.3.1 psutil==4.3.1
# homeassistant.components.wink # homeassistant.components.wink
# homeassistant.components.binary_sensor.wink
# homeassistant.components.cover.wink
# homeassistant.components.garage_door.wink
# homeassistant.components.light.wink
# homeassistant.components.lock.wink
# homeassistant.components.rollershutter.wink
# homeassistant.components.sensor.wink
# homeassistant.components.switch.wink
pubnub==3.8.2 pubnub==3.8.2
# homeassistant.components.notify.pushbullet # homeassistant.components.notify.pushbullet
@ -395,15 +387,7 @@ python-telegram-bot==5.0.0
python-twitch==1.3.0 python-twitch==1.3.0
# homeassistant.components.wink # homeassistant.components.wink
# homeassistant.components.binary_sensor.wink python-wink==0.7.15
# homeassistant.components.cover.wink
# homeassistant.components.garage_door.wink
# homeassistant.components.light.wink
# homeassistant.components.lock.wink
# homeassistant.components.rollershutter.wink
# homeassistant.components.sensor.wink
# homeassistant.components.switch.wink
python-wink==0.7.14
# homeassistant.components.keyboard # homeassistant.components.keyboard
# pyuserinput==0.1.11 # pyuserinput==0.1.11