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

Add lightwave components for switches and lights #18026

Merged
merged 25 commits into from Dec 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
154bfcc
Added lightwave components for switches and lights.
GeoffAtHome Oct 30, 2018
3810820
Address warnings raised by Hound
Oct 31, 2018
102bf58
Correcting lint messages and major typo. This time tested before commit.
GeoffAtHome Oct 31, 2018
c366c5d
Trying to fix author
GeoffAtHome Oct 31, 2018
451a40f
Minor lint changes
GeoffAtHome Oct 31, 2018
6b12336
Attempt to correct other lint error.
GeoffAtHome Nov 2, 2018
bc0a6c3
Another lint attempt.
GeoffAtHome Nov 2, 2018
a921147
More lint issues.
GeoffAtHome Nov 3, 2018
d93e6cf
Last two lint errors! Hurrah.
GeoffAtHome Nov 3, 2018
faeef0e
Changes after review from fabaff.
GeoffAtHome Nov 12, 2018
3bd6f5c
Moved device dependent code to PyPi.
GeoffAtHome Nov 24, 2018
9667ae0
Replaced DEPENDENCIES with REQUIREMENTS
GeoffAtHome Nov 25, 2018
ef25b9a
Updated following code review from Martin Hjelmare.
GeoffAtHome Nov 25, 2018
369f410
Added lightwave to requirements_all.txt
GeoffAtHome Nov 25, 2018
073592b
Omit lightwave from tests.
GeoffAtHome Nov 25, 2018
e728ab5
Updated requirements_all.txt
GeoffAtHome Nov 26, 2018
f5c2de6
Refactored how lightwave lights and switches load.
GeoffAtHome Nov 30, 2018
037c626
Removed imports that were no longer required.
GeoffAtHome Nov 30, 2018
c9d8ae0
Add guard for no discovery_info.
GeoffAtHome Dec 1, 2018
b08f076
Make it a guard clause and save indentation. Rename LRFxxx to LWRFxxx.
GeoffAtHome Dec 1, 2018
533e1e9
Sorted imports to match style guidelines.
GeoffAtHome Dec 1, 2018
1dee677
Correct return value.
GeoffAtHome Dec 1, 2018
1b7d3a6
Update requirements_all.txt
GeoffAtHome Dec 1, 2018
115a929
Catch case where we have no lights or switches configured.
GeoffAtHome Dec 1, 2018
f84a9fa
Improve configuration validation.
GeoffAtHome Dec 2, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .coveragerc
Expand Up @@ -200,6 +200,9 @@ omit =
homeassistant/components/linode.py
homeassistant/components/*/linode.py

homeassistant/components/lightwave.py
homeassistant/components/*/lightwave.py

homeassistant/components/logi_circle.py
homeassistant/components/*/logi_circle.py

Expand Down
88 changes: 88 additions & 0 deletions homeassistant/components/light/lightwave.py
@@ -0,0 +1,88 @@
"""
Implements LightwaveRF lights.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.lightwave/
"""
GeoffAtHome marked this conversation as resolved.
Show resolved Hide resolved
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.components.lightwave import LIGHTWAVE_LINK
from homeassistant.const import CONF_NAME

DEPENDENCIES = ['lightwave']

MAX_BRIGHTNESS = 255


async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Find and return LightWave lights."""
if not discovery_info:
GeoffAtHome marked this conversation as resolved.
Show resolved Hide resolved
return

lights = []
GeoffAtHome marked this conversation as resolved.
Show resolved Hide resolved
lwlink = hass.data[LIGHTWAVE_LINK]

for device_id, device_config in discovery_info.items():
name = device_config[CONF_NAME]
lights.append(LWRFLight(name, device_id, lwlink))

async_add_entities(lights)


class LWRFLight(Light):
"""Representation of a LightWaveRF light."""

def __init__(self, name, device_id, lwlink):
"""Initialize LWRFLight entity."""
self._name = name
self._device_id = device_id
self._state = None
self._brightness = MAX_BRIGHTNESS
self._lwlink = lwlink

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS

@property
def should_poll(self):
"""No polling needed for a LightWave light."""
return False

@property
def name(self):
"""Lightwave light name."""
return self._name

@property
def brightness(self):
"""Brightness of this light between 0..MAX_BRIGHTNESS."""
return self._brightness

@property
def is_on(self):
"""Lightwave light is on state."""
return self._state

async def async_turn_on(self, **kwargs):
"""Turn the LightWave light on."""
self._state = True

if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]

if self._brightness != MAX_BRIGHTNESS:
self._lwlink.turn_on_with_brightness(
self._device_id, self._name, self._brightness)
else:
self._lwlink.turn_on_light(self._device_id, self._name)

self.async_schedule_update_ha_state()

async def async_turn_off(self, **kwargs):
"""Turn the LightWave light off."""
self._state = False
self._lwlink.turn_off(self._device_id, self._name)
self.async_schedule_update_ha_state()
49 changes: 49 additions & 0 deletions homeassistant/components/lightwave.py
@@ -0,0 +1,49 @@
"""
Support for device connected via Lightwave WiFi-link hub.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/lightwave/
"""
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (CONF_HOST, CONF_LIGHTS, CONF_NAME,
CONF_SWITCHES)
from homeassistant.helpers.discovery import async_load_platform

REQUIREMENTS = ['lightwave==0.15']
LIGHTWAVE_LINK = 'lightwave_link'
DOMAIN = 'lightwave'


CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema(
cv.has_at_least_one_key(CONF_LIGHTS, CONF_SWITCHES), {
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_LIGHTS, default={}): {
cv.string: vol.Schema({vol.Required(CONF_NAME): cv.string}),
},
vol.Optional(CONF_SWITCHES, default={}): {
cv.string: vol.Schema({vol.Required(CONF_NAME): cv.string}),
}
})
}, extra=vol.ALLOW_EXTRA)


async def async_setup(hass, config):
"""Try to start embedded Lightwave broker."""
from lightwave.lightwave import LWLink

host = config[DOMAIN][CONF_HOST]
hass.data[LIGHTWAVE_LINK] = LWLink(host)

lights = config[DOMAIN][CONF_LIGHTS]
if lights:
hass.async_create_task(async_load_platform(
hass, 'light', DOMAIN, lights, config))

switches = config[DOMAIN][CONF_SWITCHES]
if switches:
hass.async_create_task(async_load_platform(
hass, 'switch', DOMAIN, switches, config))

return True
65 changes: 65 additions & 0 deletions homeassistant/components/switch/lightwave.py
@@ -0,0 +1,65 @@
"""
Implements LightwaveRF switches.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.lightwave/
"""
from homeassistant.components.lightwave import LIGHTWAVE_LINK
from homeassistant.components.switch import SwitchDevice
from homeassistant.const import CONF_NAME

DEPENDENCIES = ['lightwave']


async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Find and return LightWave switches."""
if not discovery_info:
return

switches = []
GeoffAtHome marked this conversation as resolved.
Show resolved Hide resolved
lwlink = hass.data[LIGHTWAVE_LINK]

for device_id, device_config in discovery_info.items():
name = device_config[CONF_NAME]
switches.append(LWRFSwitch(name, device_id, lwlink))

async_add_entities(switches)


class LWRFSwitch(SwitchDevice):
"""Representation of a LightWaveRF switch."""

def __init__(self, name, device_id, lwlink):
"""Initialize LWRFSwitch entity."""
self._name = name
self._device_id = device_id
self._state = None
self._lwlink = lwlink

@property
def should_poll(self):
"""No polling needed for a LightWave light."""
return False

@property
def name(self):
"""Lightwave switch name."""
return self._name

@property
def is_on(self):
"""Lightwave switch is on state."""
return self._state

async def async_turn_on(self, **kwargs):
"""Turn the LightWave switch on."""
self._state = True
self._lwlink.turn_on_switch(self._device_id, self._name)
self.async_schedule_update_ha_state()

async def async_turn_off(self, **kwargs):
"""Turn the LightWave switch off."""
self._state = False
self._lwlink.turn_off(self._device_id, self._name)
self.async_schedule_update_ha_state()
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -564,6 +564,9 @@ liffylights==0.9.4
# homeassistant.components.light.osramlightify
lightify==1.0.6.1

# homeassistant.components.lightwave
lightwave==0.15

# homeassistant.components.light.limitlessled
limitlessled==1.1.3

Expand Down