Skip to content
Closed
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 @@ -713,6 +713,7 @@ omit =
homeassistant/components/uber/sensor.py
homeassistant/components/ubus/device_tracker.py
homeassistant/components/ue_smart_radio/media_player.py
homeassistant/components/unifiled/*
homeassistant/components/upcloud/*
homeassistant/components/upnp/*
homeassistant/components/upc_connect/*
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ homeassistant/components/twentemilieu/* @frenck
homeassistant/components/twilio_call/* @robbiet480
homeassistant/components/twilio_sms/* @robbiet480
homeassistant/components/unifi/* @kane610
homeassistant/components/unifiled/* @florisvdk
homeassistant/components/upc_connect/* @pvizeli
homeassistant/components/upcloud/* @scop
homeassistant/components/updater/* @home-assistant/core
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/unifiled/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Unifi LED Lights integration."""
113 changes: 113 additions & 0 deletions homeassistant/components/unifiled/light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Support for Unifi Led lights."""
import logging

import voluptuous as vol

from unifiled import unifiled
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
Light,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

# Validation of the user's configuration
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PORT, default="20443"): cv.string,
}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Unifi LED platform."""

# Assign configuration variables.
# The configuration check takes care they are present.
_ip = config[CONF_HOST]
_port = config[CONF_PORT]
_username = config[CONF_USERNAME]
_password = config[CONF_PASSWORD]

api = unifiled(_ip, _port, username=_username, password=_password)

# Verify that passed in configuration works
if not api.getloginstate():
_LOGGER.error("Could not connect to unifiled controller")
return

# Add devices
add_entities(UnifiLedLight(light, api) for light in api.getlights())


class UnifiLedLight(Light):
"""Representation of an unifiled Light."""

def __init__(self, light, api):
"""Init Unifi LED Light."""

self._api = api
self._light = light
self._name = light["name"]
self._unique_id = light["id"]
self._state = light["status"]["output"]
self._available = self._api.getlightavailable(self._unique_id)
self._brightness = self._api.convertfrom100to255(light["status"]["led"])
self._features = SUPPORT_BRIGHTNESS

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

@property
def available(self):
"""Return the available state of this light."""
return self._available

@property
def brightness(self):
"""Return the brightness of this light."""
return self._brightness

@property
def unique_id(self):
"""Return the unique id of this light."""
return self._unique_id

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

@property
def supported_features(self):
"""Return the supported features of this light."""
return self._features

def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
self._api.setdevicebrightness(
self._unique_id,
str(self._api.convertfrom255to100(kwargs.get(ATTR_BRIGHTNESS, 255))),
)
self._api.setdeviceoutput(self._unique_id, 1)

def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._api.setdeviceoutput(self._unique_id, 0)

def update(self):
"""Update the light states."""
self._state = self._api.getlightstate(self._unique_id)
self._brightness = self._api.convertfrom100to255(
self._api.getlightbrightness(self._unique_id)
)
self._available = self._api.getlightavailable(self._unique_id)
8 changes: 8 additions & 0 deletions homeassistant/components/unifiled/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "unifiled",
"name": "Unifi LED",
"documentation": "https://www.home-assistant.io/components/unifiled",
"dependencies": [],
"codeowners": ["@florisvdk"],
"requirements": ["unifiled==0.11"]
}
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,9 @@ twentemilieu==0.1.0
# homeassistant.components.twilio
twilio==6.19.1

# homeassistant.components.unifiled
unifiled==0.11

# homeassistant.components.upcloud
upcloud-api==0.4.3

Expand Down