Skip to content
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
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ omit =
homeassistant/components/light/lw12wifi.py
homeassistant/components/light/mystrom.py
homeassistant/components/light/nanoleaf_aurora.py
homeassistant/components/light/niko_home_control.py
homeassistant/components/light/opple.py
homeassistant/components/light/osramlightify.py
homeassistant/components/light/piglow.py
Expand Down
89 changes: 89 additions & 0 deletions homeassistant/components/light/niko_home_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
Support for Niko Home Control.

For more details about this platform, please refer to the documentation
https://home-assistant.io/components/light.niko_home_control/
"""
import logging
import socket

import voluptuous as vol

from homeassistant.components.light import (
ATTR_BRIGHTNESS, PLATFORM_SCHEMA, Light)
from homeassistant.const import CONF_HOST
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['niko-home-control==0.1.8']

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have renamed add_devices to add_entities.

"""Set up the Niko Home Control light platform."""
import nikohomecontrol

host = config.get(CONF_HOST)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dict[key] for required config keys.


try:
hub = nikohomecontrol.Hub({
'ip': host,
'port': 8000,
'timeout': 20000,
'events': True
})
except socket.error as err:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Socket error is deprecated in favor of OSError in modern versions of Python 3.

_LOGGER.error("Unable to access %s (%s)", host, err)
raise PlatformNotReady

add_devices(
[NikoHomeControlLight(light, hub) for light in hub.list_actions()],
True)


class NikoHomeControlLight(Light):
"""Representation of an Niko Light."""

def __init__(self, light, nhc):
"""Set up the Niko Home Control light platform."""
self._nhc = nhc
self._light = light
self._name = light.name
self._state = None
self._brightness = None

@property
def name(self):
"""Return the display name of this light."""
return self._name

@property
def brightness(self):
"""Return the brightness of the light."""
return self._brightness
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this updated?


@property
def is_on(self):
"""Return true if light is on."""
return self._state

def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
self._light.brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
self._light.turn_on()
self._state = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be updated by self.update in the end of the service call.


def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._light.turn_off()
self._state = False
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.


def update(self):
"""Fetch new state data for this light."""
self._light.update()
self._state = self._light.is_on
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ netdisco==2.2.0
# homeassistant.components.sensor.neurio_energy
neurio==0.3.1

# homeassistant.components.light.niko_home_control
niko-home-control==0.1.8

# homeassistant.components.sensor.nederlandse_spoorwegen
nsapi==2.7.4

Expand Down