mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Improve type hints in hive lights (#76025)
This commit is contained in:
parent
fbde347e64
commit
1806172551
@ -139,7 +139,7 @@ def refresh_system(
|
|||||||
class HiveEntity(Entity):
|
class HiveEntity(Entity):
|
||||||
"""Initiate Hive Base Class."""
|
"""Initiate Hive Base Class."""
|
||||||
|
|
||||||
def __init__(self, hive, hive_device):
|
def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
|
||||||
"""Initialize the instance."""
|
"""Initialize the instance."""
|
||||||
self.hive = hive
|
self.hive = hive
|
||||||
self.device = hive_device
|
self.device = hive_device
|
||||||
@ -153,9 +153,9 @@ class HiveEntity(Entity):
|
|||||||
sw_version=self.device["deviceData"]["version"],
|
sw_version=self.device["deviceData"]["version"],
|
||||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||||
)
|
)
|
||||||
self.attributes = {}
|
self.attributes: dict[str, Any] = {}
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""When entity is added to Home Assistant."""
|
"""When entity is added to Home Assistant."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
|
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
@ -18,6 +19,9 @@ import homeassistant.util.color as color_util
|
|||||||
from . import HiveEntity, refresh_system
|
from . import HiveEntity, refresh_system
|
||||||
from .const import ATTR_MODE, DOMAIN
|
from .const import ATTR_MODE, DOMAIN
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from apyhiveapi import Hive
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
|
||||||
@ -27,7 +31,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Hive thermostat based on a config entry."""
|
"""Set up Hive thermostat based on a config entry."""
|
||||||
|
|
||||||
hive = hass.data[DOMAIN][entry.entry_id]
|
hive: Hive = hass.data[DOMAIN][entry.entry_id]
|
||||||
devices = hive.session.deviceList.get("light")
|
devices = hive.session.deviceList.get("light")
|
||||||
entities = []
|
entities = []
|
||||||
if devices:
|
if devices:
|
||||||
@ -39,7 +43,7 @@ async def async_setup_entry(
|
|||||||
class HiveDeviceLight(HiveEntity, LightEntity):
|
class HiveDeviceLight(HiveEntity, LightEntity):
|
||||||
"""Hive Active Light Device."""
|
"""Hive Active Light Device."""
|
||||||
|
|
||||||
def __init__(self, hive, hive_device):
|
def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
|
||||||
"""Initialise hive light."""
|
"""Initialise hive light."""
|
||||||
super().__init__(hive, hive_device)
|
super().__init__(hive, hive_device)
|
||||||
if self.device["hiveType"] == "warmwhitelight":
|
if self.device["hiveType"] == "warmwhitelight":
|
||||||
@ -55,22 +59,22 @@ class HiveDeviceLight(HiveEntity, LightEntity):
|
|||||||
self._attr_max_mireds = 370
|
self._attr_max_mireds = 370
|
||||||
|
|
||||||
@refresh_system
|
@refresh_system
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
new_brightness = None
|
new_brightness = None
|
||||||
new_color_temp = None
|
new_color_temp = None
|
||||||
new_color = None
|
new_color = None
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
tmp_new_brightness = kwargs.get(ATTR_BRIGHTNESS)
|
tmp_new_brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
percentage_brightness = (tmp_new_brightness / 255) * 100
|
percentage_brightness = (tmp_new_brightness / 255) * 100
|
||||||
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
|
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
|
||||||
if new_brightness == 0:
|
if new_brightness == 0:
|
||||||
new_brightness = 5
|
new_brightness = 5
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
tmp_new_color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
tmp_new_color_temp = kwargs[ATTR_COLOR_TEMP]
|
||||||
new_color_temp = round(1000000 / tmp_new_color_temp)
|
new_color_temp = round(1000000 / tmp_new_color_temp)
|
||||||
if ATTR_HS_COLOR in kwargs:
|
if ATTR_HS_COLOR in kwargs:
|
||||||
get_new_color = kwargs.get(ATTR_HS_COLOR)
|
get_new_color = kwargs[ATTR_HS_COLOR]
|
||||||
hue = int(get_new_color[0])
|
hue = int(get_new_color[0])
|
||||||
saturation = int(get_new_color[1])
|
saturation = int(get_new_color[1])
|
||||||
new_color = (hue, saturation, 100)
|
new_color = (hue, saturation, 100)
|
||||||
@ -80,11 +84,11 @@ class HiveDeviceLight(HiveEntity, LightEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@refresh_system
|
@refresh_system
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn off."""
|
"""Instruct the light to turn off."""
|
||||||
await self.hive.light.turnOff(self.device)
|
await self.hive.light.turnOff(self.device)
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self) -> None:
|
||||||
"""Update all Node data from Hive."""
|
"""Update all Node data from Hive."""
|
||||||
await self.hive.session.updateData(self.device)
|
await self.hive.session.updateData(self.device)
|
||||||
self.device = await self.hive.light.getLight(self.device)
|
self.device = await self.hive.light.getLight(self.device)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user