Bug fixes for Wink

This commit is contained in:
Paulus Schoutsen committed 2015-01-15 21:25:24 -08:00
1 parent c116cb095d
commit 702498ca09
7 files changed
+193 -140

No files matched your search

+2 -2
View File
@@ -178,7 +178,7 @@ def setup(hass, config):
_LOGGER.info("Updating light states")
for light in lights.values():
light.update_ha_state(hass)
light.update_ha_state(hass, True)
update_lights_state(None)
@@ -196,7 +196,7 @@ def setup(hass, config):
for light in discovered:
if light is not None and light not in lights.values():
light.entity_id = util.ensure_unique_string(
ENTITY_ID_FORMAT.format(util.slugify(light.get_name())),
ENTITY_ID_FORMAT.format(util.slugify(light.name)),
lights.keys())
lights[light.entity_id] = light
+22 -22
View File
@@ -4,8 +4,9 @@ import logging
# pylint: disable=no-name-in-module, import-error
import homeassistant.external.wink.pywink as pywink
from homeassistant.helpers import ToggleDevice
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_ACCESS_TOKEN
from homeassistant.components.light import ATTR_BRIGHTNESS
from homeassistant.components.wink import WinkToggleDevice
from homeassistant.const import CONF_ACCESS_TOKEN
# pylint: disable=unused-argument
@@ -35,29 +36,28 @@ def get_lights():
return [WinkLight(light) for light in pywink.get_bulbs()]
class WinkLight(ToggleDevice):
class WinkLight(WinkToggleDevice):
""" Represents a Wink light """
def __init__(self, wink):
self.wink = wink
self.state_attr = {ATTR_FRIENDLY_NAME: wink.name()}
def get_name(self):
""" Returns the name of the light if any. """
return self.wink.name()
# pylint: disable=too-few-public-methods
def turn_on(self, **kwargs):
""" Turns the light on. """
self.wink.setState(True)
""" Turns the switch on. """
brightness = kwargs.get(ATTR_BRIGHTNESS)
def turn_off(self):
""" Turns the light off. """
self.wink.setState(False)
if brightness is not None:
self.wink.setState(True, brightness / 255)
def is_on(self):
""" True if light is on. """
return self.wink.state()
else:
self.wink.setState(True)
def get_state_attributes(self):
""" Returns optional state attributes. """
return self.state_attr
@property
def state_attributes(self):
attr = super().state_attributes
if self.is_on:
brightness = self.wink.brightness()
if brightness is not None:
attr[ATTR_BRIGHTNESS] = int(brightness * 255)
return attr
+1 -1
View File
@@ -73,7 +73,7 @@ def setup(hass, config):
logger.info("Updating switch states")
for switch in switches.values():
switch.update_ha_state(hass)
switch.update_ha_state(hass, True)
update_states(None)
+5 -1
View File
@@ -86,7 +86,7 @@ class WemoSwitch(ToggleDevice):
@property
def is_on(self):
""" True if switch is on. """
return self.wemo.get_state(True)
return self.wemo.get_state()
def turn_on(self, **kwargs):
""" Turns the switch on. """
@@ -95,3 +95,7 @@ class WemoSwitch(ToggleDevice):
def turn_off(self):
""" Turns the switch off. """
self.wemo.off()
def update(self):
""" Update Wemo state. """
self.wemo.get_state(True)
+3 -31
View File
@@ -4,8 +4,8 @@ import logging
# pylint: disable=no-name-in-module, import-error
import homeassistant.external.wink.pywink as pywink
from homeassistant.helpers import ToggleDevice
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_ACCESS_TOKEN
from homeassistant.components.wink import WinkToggleDevice
from homeassistant.const import CONF_ACCESS_TOKEN
# pylint: disable=unused-argument
@@ -32,32 +32,4 @@ def devices_discovered(hass, config, info):
def get_switches():
""" Returns the Wink switches. """
return [WinkSwitch(switch) for switch in pywink.get_switches()]
class WinkSwitch(ToggleDevice):
""" represents a WeMo switch within home assistant. """
def __init__(self, wink):
self.wink = wink
self.state_attr = {ATTR_FRIENDLY_NAME: wink.name()}
def get_name(self):
""" Returns the name of the switch if any. """
return self.wink.name()
def turn_on(self, **kwargs):
""" Turns the switch on. """
self.wink.setState(True)
def turn_off(self):
""" Turns the switch off. """
self.wink.setState(False)
def is_on(self):
""" True if switch is on. """
return self.wink.state()
def get_state_attributes(self):
""" Returns optional state attributes. """
return self.state_attr
return [WinkToggleDevice(switch) for switch in pywink.get_switches()]
+44 -3
View File
@@ -8,10 +8,10 @@ import homeassistant.external.wink.pywink as pywink
from homeassistant import bootstrap
from homeassistant.loader import get_component
from homeassistant.helpers import validate_config
from homeassistant.helpers import validate_config, ToggleDevice
from homeassistant.const import (
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED,
CONF_ACCESS_TOKEN)
EVENT_PLATFORM_DISCOVERED, CONF_ACCESS_TOKEN,
ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME)
DOMAIN = "wink"
DEPENDENCIES = []
@@ -48,3 +48,44 @@ def setup(hass, config):
})
return True
class WinkToggleDevice(ToggleDevice):
""" represents a WeMo switch within home assistant. """
def __init__(self, wink):
self.wink = wink
@property
def unique_id(self):
""" Returns the id of this WeMo switch """
return "{}.{}".format(self.__class__, self.wink.deviceId())
@property
def name(self):
""" Returns the name of the light if any. """
return self.wink.name()
@property
def is_on(self):
""" True if light is on. """
return self.wink.state()
@property
def state_attributes(self):
""" Returns optional state attributes. """
return {
ATTR_FRIENDLY_NAME: self.wink.name()
}
def turn_on(self, **kwargs):
""" Turns the switch on. """
self.wink.setState(True)
def turn_off(self):
""" Turns the switch off. """
self.wink.setState(False)
def update(self):
""" Update state of the light. """
self.wink.wait_till_desired_reached()