mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Improve type hints in vesync lights (#75998)
* Improve type hints in vesync lights * Adjust import
This commit is contained in:
parent
98f0b24c42
commit
1ba18f8df6
@ -21,7 +21,7 @@ from .const import (
|
||||
VS_SWITCHES,
|
||||
)
|
||||
|
||||
PLATFORMS = [Platform.SWITCH, Platform.FAN, Platform.LIGHT, Platform.SENSOR]
|
||||
PLATFORMS = [Platform.FAN, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
"""Common utilities for VeSync Component."""
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.entity import Entity, ToggleEntity
|
||||
from pyvesync.vesyncbasedevice import VeSyncBaseDevice
|
||||
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity, ToggleEntity
|
||||
|
||||
from .const import DOMAIN, VS_FANS, VS_LIGHTS, VS_SENSORS, VS_SWITCHES
|
||||
|
||||
@ -48,7 +51,7 @@ async def async_process_devices(hass, manager):
|
||||
class VeSyncBaseEntity(Entity):
|
||||
"""Base class for VeSync Entity Representations."""
|
||||
|
||||
def __init__(self, device):
|
||||
def __init__(self, device: VeSyncBaseDevice) -> None:
|
||||
"""Initialize the VeSync device."""
|
||||
self.device = device
|
||||
self._attr_unique_id = self.base_unique_id
|
||||
@ -65,7 +68,7 @@ class VeSyncBaseEntity(Entity):
|
||||
return self.device.cid
|
||||
|
||||
@property
|
||||
def base_name(self):
|
||||
def base_name(self) -> str:
|
||||
"""Return the name of the device."""
|
||||
# Same story here as `base_unique_id` above
|
||||
return self.device.device_name
|
||||
@ -76,17 +79,17 @@ class VeSyncBaseEntity(Entity):
|
||||
return self.device.connection_status == "online"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.base_unique_id)},
|
||||
"name": self.base_name,
|
||||
"model": self.device.device_type,
|
||||
"default_manufacturer": "VeSync",
|
||||
"sw_version": self.device.current_firm_version,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.base_unique_id)},
|
||||
name=self.base_name,
|
||||
model=self.device.device_type,
|
||||
default_manufacturer="VeSync",
|
||||
sw_version=self.device.current_firm_version,
|
||||
)
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update vesync device."""
|
||||
self.device.update()
|
||||
|
||||
@ -100,10 +103,10 @@ class VeSyncDevice(VeSyncBaseEntity, ToggleEntity):
|
||||
return self.device.details
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return True if device is on."""
|
||||
return self.device.device_status == "on"
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
self.device.turn_off()
|
||||
|
@ -67,7 +67,7 @@ class VeSyncBaseLight(VeSyncDevice, LightEntity):
|
||||
"""Base class for VeSync Light Devices Representations."""
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Get light brightness."""
|
||||
# get value from pyvesync library api,
|
||||
result = self.device.brightness
|
||||
@ -141,10 +141,12 @@ class VeSyncTunableWhiteLightHA(VeSyncBaseLight, LightEntity):
|
||||
"""Representation of a VeSync Tunable White Light device."""
|
||||
|
||||
_attr_color_mode = ColorMode.COLOR_TEMP
|
||||
_attr_max_mireds = 370 # 1,000,000 divided by 2700 Kelvin = 370 Mireds
|
||||
_attr_min_mireds = 154 # 1,000,000 divided by 6500 Kelvin = 154 Mireds
|
||||
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
def color_temp(self) -> int:
|
||||
"""Get device white temperature."""
|
||||
# get value from pyvesync library api,
|
||||
result = self.device.color_temp_pct
|
||||
@ -169,13 +171,3 @@ class VeSyncTunableWhiteLightHA(VeSyncBaseLight, LightEntity):
|
||||
)
|
||||
# ensure value between minimum and maximum Mireds
|
||||
return max(self.min_mireds, min(color_temp_value, self.max_mireds))
|
||||
|
||||
@property
|
||||
def min_mireds(self):
|
||||
"""Set device coldest white temperature."""
|
||||
return 154 # 154 Mireds ( 1,000,000 divided by 6500 Kelvin = 154 Mireds)
|
||||
|
||||
@property
|
||||
def max_mireds(self):
|
||||
"""Set device warmest white temperature."""
|
||||
return 370 # 370 Mireds ( 1,000,000 divided by 2700 Kelvin = 370 Mireds)
|
||||
|
Loading…
x
Reference in New Issue
Block a user