mirror of
https://github.com/home-assistant/core
synced 2024-09-09 12:51:22 +02:00
Improve type hints in freedompro lights (#76045)
This commit is contained in:
parent
c8f11d65d2
commit
46d3f2e14c
@ -1,5 +1,8 @@
|
||||
"""Support for Freedompro light."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from pyfreedompro import put_state
|
||||
|
||||
@ -17,6 +20,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import FreedomproDataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
@ -24,8 +28,8 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Freedompro light."""
|
||||
api_key = entry.data[CONF_API_KEY]
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
api_key: str = entry.data[CONF_API_KEY]
|
||||
coordinator: FreedomproDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
Device(hass, api_key, device, coordinator)
|
||||
for device in coordinator.data
|
||||
@ -36,7 +40,13 @@ async def async_setup_entry(
|
||||
class Device(CoordinatorEntity, LightEntity):
|
||||
"""Representation of an Freedompro light."""
|
||||
|
||||
def __init__(self, hass, api_key, device, coordinator):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
api_key: str,
|
||||
device: dict[str, Any],
|
||||
coordinator: FreedomproDataUpdateCoordinator,
|
||||
) -> None:
|
||||
"""Initialize the Freedompro light."""
|
||||
super().__init__(coordinator)
|
||||
self._session = aiohttp_client.async_get_clientsession(hass)
|
||||
@ -44,9 +54,7 @@ class Device(CoordinatorEntity, LightEntity):
|
||||
self._attr_name = device["name"]
|
||||
self._attr_unique_id = device["uid"]
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={
|
||||
(DOMAIN, self.unique_id),
|
||||
},
|
||||
identifiers={(DOMAIN, device["uid"])},
|
||||
manufacturer="Freedompro",
|
||||
model=device["type"],
|
||||
name=self.name,
|
||||
@ -87,31 +95,29 @@ class Device(CoordinatorEntity, LightEntity):
|
||||
await super().async_added_to_hass()
|
||||
self._handle_coordinator_update()
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Async function to set on to light."""
|
||||
payload = {"on": True}
|
||||
payload: dict[str, Any] = {"on": True}
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
payload["brightness"] = round(kwargs[ATTR_BRIGHTNESS] / 255 * 100)
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
payload["saturation"] = round(kwargs[ATTR_HS_COLOR][1])
|
||||
payload["hue"] = round(kwargs[ATTR_HS_COLOR][0])
|
||||
payload = json.dumps(payload)
|
||||
await put_state(
|
||||
self._session,
|
||||
self._api_key,
|
||||
self._attr_unique_id,
|
||||
payload,
|
||||
json.dumps(payload),
|
||||
)
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Async function to set off to light."""
|
||||
payload = {"on": False}
|
||||
payload = json.dumps(payload)
|
||||
await put_state(
|
||||
self._session,
|
||||
self._api_key,
|
||||
self._attr_unique_id,
|
||||
payload,
|
||||
json.dumps(payload),
|
||||
)
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
Loading…
Reference in New Issue
Block a user