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

Update pyhomematic to 0.1.52 and add features for lights #18499

Merged
merged 5 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions homeassistant/components/homematic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['pyhomematic==0.1.51']
REQUIREMENTS = ['pyhomematic==0.1.52']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,8 +64,9 @@
DISCOVER_SWITCHES: [
'Switch', 'SwitchPowermeter', 'IOSwitch', 'IPSwitch', 'RFSiren',
'IPSwitchPowermeter', 'HMWIOSwitch', 'Rain', 'EcoLogic',
'IPKeySwitchPowermeter'],
DISCOVER_LIGHTS: ['Dimmer', 'KeyDimmer', 'IPKeyDimmer'],
'IPKeySwitchPowermeter', 'IPGarage'],
DISCOVER_LIGHTS: ['Dimmer', 'KeyDimmer', 'IPKeyDimmer', 'IPDimmer',
'ColorEffectLight'],
DISCOVER_SENSORS: [
'SwitchPowermeter', 'Motion', 'MotionV2', 'RemoteMotion', 'MotionIP',
'ThermostatWall', 'AreaThermostat', 'RotaryHandleSensor',
Expand All @@ -76,7 +77,7 @@
'IPSmoke', 'RFSiren', 'PresenceIP', 'IPAreaThermostat',
'IPWeatherSensor', 'RotaryHandleSensorIP', 'IPPassageSensor',
'IPKeySwitchPowermeter', 'IPThermostatWall230V', 'IPWeatherSensorPlus',
'IPWeatherSensorBasic', 'IPBrightnessSensor'],
'IPWeatherSensorBasic', 'IPBrightnessSensor', 'IPGarage'],
DISCOVER_CLIMATE: [
'Thermostat', 'ThermostatWall', 'MAXThermostat', 'ThermostatWall2',
'MAXWallThermostat', 'IPThermostat', 'IPThermostatWall',
Expand Down
48 changes: 41 additions & 7 deletions homeassistant/components/light/homematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from homeassistant.components.homematic import ATTR_DISCOVER_DEVICES, HMDevice
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.const import STATE_UNKNOWN
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_COLOR,
ATTR_EFFECT, SUPPORT_EFFECT, Light)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -38,7 +38,7 @@ class HMLight(HMDevice, Light):
def brightness(self):
"""Return the brightness of this light between 0..255."""
# Is dimmer?
if self._state == "LEVEL":
if self._state == 'LEVEL':
return int(self._hm_get_state() * 255)
return None

Expand All @@ -53,16 +53,47 @@ def is_on(self):
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_HOMEMATIC
if 'COLOR' in self._hmdevice.WRITENODE:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT
return SUPPORT_BRIGHTNESS

@property
def hs_color(self):
"""Return the hue and saturation color value [float, float]."""
if not self.supported_features & SUPPORT_COLOR:
return None
hue, sat = self._hmdevice.get_hs_color()
return hue*360.0, sat*100.0

@property
def effect_list(self):
"""Return the list of supported effects."""
if not self.supported_features & SUPPORT_EFFECT:
return None
return self._hmdevice.get_effect_list()

@property
def effect(self):
"""Return the current color change program of the light."""
if not self.supported_features & SUPPORT_EFFECT:
return None
return self._hmdevice.get_effect()

def turn_on(self, **kwargs):
"""Turn the light on."""
"""Turn the light on and/or change color or color effect settings."""
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
self._hmdevice.set_level(percent_bright, self._channel)
else:
elif ATTR_HS_COLOR not in kwargs and ATTR_EFFECT not in kwargs:
self._hmdevice.on(self._channel)

if ATTR_HS_COLOR in kwargs:
self._hmdevice.set_hs_color(
hue=kwargs[ATTR_HS_COLOR][0]/360.0,
saturation=kwargs[ATTR_HS_COLOR][1]/100.0)
if ATTR_EFFECT in kwargs:
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])

def turn_off(self, **kwargs):
"""Turn the light off."""
self._hmdevice.off(self._channel)
Expand All @@ -71,4 +102,7 @@ def _init_data_struct(self):
"""Generate a data dict (self._data) from the Homematic metadata."""
# Use LEVEL
self._state = "LEVEL"
self._data.update({self._state: STATE_UNKNOWN})
self._data[self._state] = None

if self.supported_features & SUPPORT_COLOR:
self._data.update({"COLOR": None, "PROGRAM": None})
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ pyhik==0.1.8
pyhiveapi==0.2.14

# homeassistant.components.homematic
pyhomematic==0.1.51
pyhomematic==0.1.52

# homeassistant.components.sensor.hydroquebec
pyhydroquebec==2.2.2
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pydeconz==47
pydispatcher==2.0.5

# homeassistant.components.homematic
pyhomematic==0.1.51
pyhomematic==0.1.52

# homeassistant.components.litejet
pylitejet==0.1
Expand Down