Add support for enabling/disabling cloud access in flux_led (#61138)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2021-12-19 00:59:16 -06:00 committed by GitHub
parent d7c5e41802
commit a6b680cd32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 428 additions and 111 deletions

View file

@ -6,18 +6,56 @@ from typing import Any
from flux_led.aiodevice import AIOWifiLedBulb
from homeassistant import config_entries
from homeassistant.const import CONF_NAME
from homeassistant.core import callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import FluxLedUpdateCoordinator
from .const import SIGNAL_STATE_UPDATED
from .const import CONF_MINOR_VERSION, CONF_MODEL, SIGNAL_STATE_UPDATED
def _async_device_info(
unique_id: str, device: AIOWifiLedBulb, entry: config_entries.ConfigEntry
) -> DeviceInfo:
version_num = device.version_num
if minor_version := entry.data.get(CONF_MINOR_VERSION):
sw_version = version_num + int(hex(minor_version)[2:]) / 100
sw_version_str = f"{sw_version:0.3f}"
else:
sw_version_str = str(device.version_num)
return DeviceInfo(
connections={(dr.CONNECTION_NETWORK_MAC, unique_id)},
manufacturer="Zengge",
model=device.model,
name=entry.data[CONF_NAME],
sw_version=sw_version_str,
hw_version=entry.data.get(CONF_MODEL),
)
class FluxBaseEntity(Entity):
"""Representation of a Flux entity without a coordinator."""
def __init__(
self,
device: AIOWifiLedBulb,
entry: config_entries.ConfigEntry,
) -> None:
"""Initialize the light."""
self._device: AIOWifiLedBulb = device
self.entry = entry
if entry.unique_id:
self._attr_device_info = _async_device_info(
entry.unique_id, self._device, entry
)
class FluxEntity(CoordinatorEntity):
"""Representation of a Flux entity."""
"""Representation of a Flux entity with a coordinator."""
coordinator: FluxLedUpdateCoordinator
@ -33,13 +71,9 @@ class FluxEntity(CoordinatorEntity):
self._responding = True
self._attr_name = name
self._attr_unique_id = unique_id
if self.unique_id:
self._attr_device_info = DeviceInfo(
connections={(dr.CONNECTION_NETWORK_MAC, self.unique_id)},
manufacturer="Magic Home (Zengge)",
model=self._device.model,
name=self.name,
sw_version=str(self._device.version_num),
if unique_id:
self._attr_device_info = _async_device_info(
unique_id, self._device, coordinator.entry
)
@property