myStrom WiFi bulbs (#7161)
* Add initial support for myStrom WiFi bulbs * Upgrade python-mystrom to 0.3.8 * Add myStrom light * Fix lint issue
This commit is contained in:
parent
5574686d74
commit
c7a11277ac
4 changed files with 126 additions and 3 deletions
|
@ -233,13 +233,14 @@ omit =
|
|||
homeassistant/components/light/lifx.py
|
||||
homeassistant/components/light/lifx_legacy.py
|
||||
homeassistant/components/light/limitlessled.py
|
||||
homeassistant/components/light/mystrom.py
|
||||
homeassistant/components/light/osramlightify.py
|
||||
homeassistant/components/light/piglow.py
|
||||
homeassistant/components/light/tikteck.py
|
||||
homeassistant/components/light/tradfri.py
|
||||
homeassistant/components/light/x10.py
|
||||
homeassistant/components/light/yeelight.py
|
||||
homeassistant/components/light/yeelightsunflower.py
|
||||
homeassistant/components/light/piglow.py
|
||||
homeassistant/components/light/zengge.py
|
||||
homeassistant/components/lirc.py
|
||||
homeassistant/components/lock/nuki.py
|
||||
|
|
121
homeassistant/components/light/mystrom.py
Normal file
121
homeassistant/components/light/mystrom.py
Normal file
|
@ -0,0 +1,121 @@
|
|||
"""
|
||||
Support for myStrom Wifi bulbs.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.mystrom/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
Light, PLATFORM_SCHEMA, ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS)
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, STATE_UNKNOWN
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['python-mystrom==0.3.8']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = 'myStrom bulb'
|
||||
|
||||
SUPPORT_MYSTROM = (SUPPORT_BRIGHTNESS)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_MAC): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the myStrom Light platform."""
|
||||
from pymystrom import MyStromBulb
|
||||
from pymystrom.exceptions import MyStromConnectionError
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
mac = config.get(CONF_MAC)
|
||||
name = config.get(CONF_NAME)
|
||||
|
||||
bulb = MyStromBulb(host, mac)
|
||||
try:
|
||||
if bulb.get_status()['type'] != 'rgblamp':
|
||||
_LOGGER.error("Device %s (%s) is not a myStrom bulb", host, mac)
|
||||
return False
|
||||
except MyStromConnectionError:
|
||||
_LOGGER.warning("myStrom bulb not online")
|
||||
|
||||
add_devices([MyStromLight(bulb, name)], True)
|
||||
|
||||
|
||||
class MyStromLight(Light):
|
||||
"""Representation of the myStrom WiFi Bulb."""
|
||||
|
||||
def __init__(self, bulb, name):
|
||||
"""Initialize the light."""
|
||||
self._bulb = bulb
|
||||
self._name = name
|
||||
self._state = None
|
||||
self._available = False
|
||||
self._brightness = 0
|
||||
self._rgb_color = [0, 0, 0]
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the display name of this light."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_MYSTROM
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Brightness of the light."""
|
||||
return self._brightness
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if light is on."""
|
||||
return self._state['on'] if self._state is not None else STATE_UNKNOWN
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn on the light."""
|
||||
from pymystrom.exceptions import MyStromConnectionError
|
||||
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
||||
|
||||
try:
|
||||
if not self.is_on:
|
||||
self._bulb.set_on()
|
||||
if brightness is not None:
|
||||
self._bulb.set_color_hsv(0, 0, round(brightness * 100 / 255))
|
||||
except MyStromConnectionError:
|
||||
_LOGGER.warning("myStrom bulb not online")
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn off the bulb."""
|
||||
from pymystrom.exceptions import MyStromConnectionError
|
||||
|
||||
try:
|
||||
self._bulb.set_off()
|
||||
except MyStromConnectionError:
|
||||
_LOGGER.warning("myStrom bulb not online")
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for this light."""
|
||||
from pymystrom.exceptions import MyStromConnectionError
|
||||
|
||||
try:
|
||||
self._state = self._bulb.get_status()
|
||||
self._brightness = int(self._bulb.get_brightness()) * 255 / 100
|
||||
self._available = True
|
||||
except MyStromConnectionError:
|
||||
_LOGGER.warning("myStrom bulb not online")
|
||||
self._available = False
|
|
@ -12,7 +12,7 @@ from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
|||
from homeassistant.const import (CONF_NAME, CONF_HOST)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['python-mystrom==0.3.6']
|
||||
REQUIREMENTS = ['python-mystrom==0.3.8']
|
||||
|
||||
DEFAULT_NAME = 'myStrom Switch'
|
||||
|
||||
|
|
|
@ -623,8 +623,9 @@ python-hpilo==3.9
|
|||
# homeassistant.components.media_player.mpd
|
||||
python-mpd2==0.5.5
|
||||
|
||||
# homeassistant.components.light.mystrom
|
||||
# homeassistant.components.switch.mystrom
|
||||
python-mystrom==0.3.6
|
||||
python-mystrom==0.3.8
|
||||
|
||||
# homeassistant.components.nest
|
||||
python-nest==3.1.0
|
||||
|
|
Loading…
Add table
Reference in a new issue