-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""The deako integration.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from pydeako.deako import Deako, FindDevicesTimeout | ||
from pydeako.discover import DeakoDiscoverer | ||
|
||
from homeassistant.components import zeroconf | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.exceptions import ConfigEntryNotReady | ||
|
||
from .const import DOMAIN | ||
|
||
_LOGGER: logging.Logger = logging.getLogger(__package__) | ||
|
||
PLATFORMS: list[Platform] = [Platform.LIGHT] | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up deako from a config entry.""" | ||
hass_data = hass.data.setdefault(DOMAIN, {}) | ||
if hass_data is None or not isinstance(hass_data, dict): | ||
hass_data = {} | ||
hass.data[DOMAIN] = hass_data | ||
|
||
_zc = await zeroconf.async_get_instance(hass) | ||
discoverer = DeakoDiscoverer(_zc) | ||
|
||
connection = Deako(discoverer.get_address) | ||
await connection.connect() | ||
try: | ||
await connection.find_devices() | ||
except FindDevicesTimeout as exc: | ||
_LOGGER.warning("No devices expected") | ||
await connection.disconnect() | ||
raise ConfigEntryNotReady(exc) from exc | ||
|
||
devices = connection.get_devices() | ||
if len(devices) == 0: | ||
await connection.disconnect() | ||
raise ConfigEntryNotReady(devices) | ||
|
||
hass.data[DOMAIN][entry.entry_id] = connection | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
await hass.data[DOMAIN][entry.entry_id].disconnect() | ||
|
||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Config flow for deako.""" | ||
|
||
from pydeako.discover import DeakoDiscoverer, DevicesNotFoundException | ||
|
||
from homeassistant.components import zeroconf | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import config_entry_flow | ||
|
||
from .const import DOMAIN, NAME | ||
|
||
|
||
async def _async_has_devices(hass: HomeAssistant) -> bool: | ||
"""Return if there are devices that can be discovered.""" | ||
_zc = await zeroconf.async_get_instance(hass) | ||
discoverer = DeakoDiscoverer(_zc) | ||
|
||
try: | ||
await discoverer.get_address() | ||
# address exists, there's at least one device | ||
return True | ||
|
||
except DevicesNotFoundException: | ||
return False | ||
|
||
|
||
config_entry_flow.register_discovery_flow(DOMAIN, NAME, _async_has_devices) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Constants for Deako.""" | ||
# Base component constants | ||
NAME = "Deako" | ||
DOMAIN = "deako" | ||
DOMAIN_DATA = f"{DOMAIN}_data" | ||
|
||
# Icons | ||
ICON = "mdi:format-quote-close" | ||
|
||
# Platforms | ||
LIGHT = "light" | ||
PLATFORMS = [LIGHT] | ||
|
||
CONNECTION_ID = "connection_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"""Binary sensor platform for integration_blueprint.""" | ||
import logging | ||
from typing import Any | ||
|
||
from pydeako.deako import Deako | ||
|
||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import DOMAIN | ||
|
||
_LOGGER: logging.Logger = logging.getLogger(__package__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config: ConfigEntry, | ||
add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Configure the platform.""" | ||
client: Deako = hass.data[DOMAIN][config.entry_id] | ||
|
||
devices = client.get_devices() | ||
if len(devices) == 0: | ||
# If deako devices are advertising on mdns, we should be able to get at least one device | ||
_LOGGER.warning("No devices found from local integration") | ||
await client.disconnect() | ||
return | ||
lights = [DeakoLightSwitch(client, uuid) for uuid in devices] | ||
add_entities(lights) | ||
|
||
|
||
class DeakoLightSwitch(LightEntity): | ||
"""Deako LightEntity class.""" | ||
|
||
client: Deako | ||
uuid: str | ||
|
||
def __init__(self, client: Deako, uuid: str) -> None: | ||
"""Save connection reference.""" | ||
self.client = client | ||
self.uuid = uuid | ||
self.client.set_state_callback(self.uuid, self.on_update) | ||
|
||
def on_update(self) -> None: | ||
"""State update callback.""" | ||
self.schedule_update_ha_state() | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
"""Returns device info in HA digestable format.""" | ||
return DeviceInfo( | ||
identifiers={(DOMAIN, self.uuid)}, | ||
name=self.name, | ||
manufacturer="Deako", | ||
model="dimmer" | ||
if ColorMode.BRIGHTNESS in self.supported_color_modes | ||
else "smart", | ||
) | ||
|
||
@property | ||
def unique_id(self) -> str: | ||
"""Return the ID of this Deako light.""" | ||
return self.uuid | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Return the name of the Deako light.""" | ||
name = self.client.get_name(self.uuid) | ||
return name or f"Unknown device: {self.uuid}" | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return true if the light is on.""" | ||
state = self.client.get_state(self.uuid) | ||
if state is not None: | ||
power = state.get("power", False) | ||
if isinstance(power, bool): | ||
return power | ||
return False | ||
|
||
@property | ||
def brightness(self) -> int: | ||
"""Return the brightness of this light between 0..255.""" | ||
state = self.client.get_state(self.uuid) | ||
if state is not None: | ||
return int(round(state.get("dim", 0) * 2.55)) | ||
return 0 | ||
|
||
@property | ||
def supported_color_modes(self) -> set[ColorMode]: | ||
"""Flag supported features.""" | ||
color_modes: set[ColorMode] = set() | ||
state = self.client.get_state(self.uuid) | ||
if state is not None and state.get("dim") is None: | ||
color_modes.add(ColorMode.ONOFF) | ||
else: | ||
color_modes.add(ColorMode.BRIGHTNESS) | ||
return color_modes | ||
|
||
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Turn on the light.""" | ||
dim = None | ||
if ATTR_BRIGHTNESS in kwargs: | ||
dim = round(kwargs[ATTR_BRIGHTNESS] / 2.55, 0) | ||
await self.client.control_device(self.uuid, True, dim) | ||
|
||
async def async_turn_off(self, **kwargs: Any) -> None: | ||
"""Turn off the device.""" | ||
dim = None | ||
if ATTR_BRIGHTNESS in kwargs: | ||
dim = round(kwargs[ATTR_BRIGHTNESS] / 2.55, 0) | ||
await self.client.control_device(self.uuid, False, dim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"domain": "deako", | ||
"name": "Deako Smart Lighting", | ||
"codeowners": ["@sebirdman", "@balake", "@deakolights"], | ||
"config_flow": true, | ||
"dependencies": ["zeroconf"], | ||
"documentation": "https://www.home-assistant.io/integrations/deako", | ||
"iot_class": "local_polling", | ||
"loggers": ["pydeako"], | ||
"requirements": ["pydeako==0.3.2"], | ||
"zeroconf": ["_deako._tcp.local."] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"config": { | ||
"step": { | ||
"confirm": { | ||
"description": "[%key:common::config_flow::description::confirm_setup%]" | ||
} | ||
}, | ||
"abort": { | ||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]", | ||
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ | |
"cpuspeed", | ||
"crownstone", | ||
"daikin", | ||
"deako", | ||
"deconz", | ||
"deluge", | ||
"denonavr", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for the Deako integration.""" |
Oops, something went wrong.