mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Improve init type hints in enocean (#92176)
This commit is contained in:
parent
8c64eda58f
commit
67a7de1869
@ -7,6 +7,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASSES_SCHEMA,
|
DEVICE_CLASSES_SCHEMA,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_DEVICE_CLASS, CONF_ID, CONF_NAME
|
from homeassistant.const import CONF_DEVICE_CLASS, CONF_ID, CONF_NAME
|
||||||
@ -37,9 +38,9 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Binary Sensor platform for EnOcean."""
|
"""Set up the Binary Sensor platform for EnOcean."""
|
||||||
dev_id = config.get(CONF_ID)
|
dev_id: list[int] = config[CONF_ID]
|
||||||
dev_name = config.get(CONF_NAME)
|
dev_name: str = config[CONF_NAME]
|
||||||
device_class = config.get(CONF_DEVICE_CLASS)
|
device_class: BinarySensorDeviceClass | None = config.get(CONF_DEVICE_CLASS)
|
||||||
|
|
||||||
add_entities([EnOceanBinarySensor(dev_id, dev_name, device_class)])
|
add_entities([EnOceanBinarySensor(dev_id, dev_name, device_class)])
|
||||||
|
|
||||||
@ -52,7 +53,12 @@ class EnOceanBinarySensor(EnOceanEntity, BinarySensorEntity):
|
|||||||
- F6-02-02 (Light and Blind Control - Application Style 1)
|
- F6-02-02 (Light and Blind Control - Application Style 1)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, dev_id, dev_name, device_class):
|
def __init__(
|
||||||
|
self,
|
||||||
|
dev_id: list[int],
|
||||||
|
dev_name: str,
|
||||||
|
device_class: BinarySensorDeviceClass | None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the EnOcean binary sensor."""
|
"""Initialize the EnOcean binary sensor."""
|
||||||
super().__init__(dev_id, dev_name)
|
super().__init__(dev_id, dev_name)
|
||||||
self._device_class = device_class
|
self._device_class = device_class
|
||||||
|
@ -11,7 +11,7 @@ from .const import SIGNAL_RECEIVE_MESSAGE, SIGNAL_SEND_MESSAGE
|
|||||||
class EnOceanEntity(Entity):
|
class EnOceanEntity(Entity):
|
||||||
"""Parent class for all entities associated with the EnOcean component."""
|
"""Parent class for all entities associated with the EnOcean component."""
|
||||||
|
|
||||||
def __init__(self, dev_id, dev_name="EnOcean device"):
|
def __init__(self, dev_id: list[int], dev_name: str) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
self.dev_id = dev_id
|
self.dev_id = dev_id
|
||||||
self.dev_name = dev_name
|
self.dev_name = dev_name
|
||||||
|
@ -41,9 +41,9 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the EnOcean light platform."""
|
"""Set up the EnOcean light platform."""
|
||||||
sender_id = config.get(CONF_SENDER_ID)
|
sender_id: list[int] = config[CONF_SENDER_ID]
|
||||||
dev_name = config.get(CONF_NAME)
|
dev_name: str = config[CONF_NAME]
|
||||||
dev_id = config.get(CONF_ID)
|
dev_id: list[int] = config[CONF_ID]
|
||||||
|
|
||||||
add_entities([EnOceanLight(sender_id, dev_id, dev_name)])
|
add_entities([EnOceanLight(sender_id, dev_id, dev_name)])
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class EnOceanLight(EnOceanEntity, LightEntity):
|
|||||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
|
|
||||||
def __init__(self, sender_id, dev_id, dev_name):
|
def __init__(self, sender_id: list[int], dev_id: list[int], dev_name: str) -> None:
|
||||||
"""Initialize the EnOcean light source."""
|
"""Initialize the EnOcean light source."""
|
||||||
super().__init__(dev_id, dev_name)
|
super().__init__(dev_id, dev_name)
|
||||||
self._on_state = False
|
self._on_state = False
|
||||||
|
@ -117,16 +117,16 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up an EnOcean sensor device."""
|
"""Set up an EnOcean sensor device."""
|
||||||
dev_id = config[CONF_ID]
|
dev_id: list[int] = config[CONF_ID]
|
||||||
dev_name = config[CONF_NAME]
|
dev_name: str = config[CONF_NAME]
|
||||||
sensor_type = config[CONF_DEVICE_CLASS]
|
sensor_type: str = config[CONF_DEVICE_CLASS]
|
||||||
|
|
||||||
entities: list[EnOceanSensor] = []
|
entities: list[EnOceanSensor] = []
|
||||||
if sensor_type == SENSOR_TYPE_TEMPERATURE:
|
if sensor_type == SENSOR_TYPE_TEMPERATURE:
|
||||||
temp_min = config[CONF_MIN_TEMP]
|
temp_min: int = config[CONF_MIN_TEMP]
|
||||||
temp_max = config[CONF_MAX_TEMP]
|
temp_max: int = config[CONF_MAX_TEMP]
|
||||||
range_from = config[CONF_RANGE_FROM]
|
range_from: int = config[CONF_RANGE_FROM]
|
||||||
range_to = config[CONF_RANGE_TO]
|
range_to: int = config[CONF_RANGE_TO]
|
||||||
entities = [
|
entities = [
|
||||||
EnOceanTemperatureSensor(
|
EnOceanTemperatureSensor(
|
||||||
dev_id,
|
dev_id,
|
||||||
@ -155,7 +155,10 @@ class EnOceanSensor(EnOceanEntity, RestoreEntity, SensorEntity):
|
|||||||
"""Representation of an EnOcean sensor device such as a power meter."""
|
"""Representation of an EnOcean sensor device such as a power meter."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, dev_id, dev_name, description: EnOceanSensorEntityDescription
|
self,
|
||||||
|
dev_id: list[int],
|
||||||
|
dev_name: str,
|
||||||
|
description: EnOceanSensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the EnOcean sensor device."""
|
"""Initialize the EnOcean sensor device."""
|
||||||
super().__init__(dev_id, dev_name)
|
super().__init__(dev_id, dev_name)
|
||||||
@ -217,14 +220,14 @@ class EnOceanTemperatureSensor(EnOceanSensor):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
dev_id,
|
dev_id: list[int],
|
||||||
dev_name,
|
dev_name: str,
|
||||||
description: EnOceanSensorEntityDescription,
|
description: EnOceanSensorEntityDescription,
|
||||||
*,
|
*,
|
||||||
scale_min,
|
scale_min: int,
|
||||||
scale_max,
|
scale_max: int,
|
||||||
range_from,
|
range_from: int,
|
||||||
range_to,
|
range_to: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the EnOcean temperature sensor device."""
|
"""Initialize the EnOcean temperature sensor device."""
|
||||||
super().__init__(dev_id, dev_name, description)
|
super().__init__(dev_id, dev_name, description)
|
||||||
|
@ -65,9 +65,9 @@ async def async_setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the EnOcean switch platform."""
|
"""Set up the EnOcean switch platform."""
|
||||||
channel = config.get(CONF_CHANNEL)
|
channel: int = config[CONF_CHANNEL]
|
||||||
dev_id = config.get(CONF_ID)
|
dev_id: list[int] = config[CONF_ID]
|
||||||
dev_name = config.get(CONF_NAME)
|
dev_name: str = config[CONF_NAME]
|
||||||
|
|
||||||
_migrate_to_new_unique_id(hass, dev_id, channel)
|
_migrate_to_new_unique_id(hass, dev_id, channel)
|
||||||
async_add_entities([EnOceanSwitch(dev_id, dev_name, channel)])
|
async_add_entities([EnOceanSwitch(dev_id, dev_name, channel)])
|
||||||
@ -76,7 +76,7 @@ async def async_setup_platform(
|
|||||||
class EnOceanSwitch(EnOceanEntity, SwitchEntity):
|
class EnOceanSwitch(EnOceanEntity, SwitchEntity):
|
||||||
"""Representation of an EnOcean switch device."""
|
"""Representation of an EnOcean switch device."""
|
||||||
|
|
||||||
def __init__(self, dev_id, dev_name, channel):
|
def __init__(self, dev_id: list[int], dev_name: str, channel: int) -> None:
|
||||||
"""Initialize the EnOcean switch device."""
|
"""Initialize the EnOcean switch device."""
|
||||||
super().__init__(dev_id, dev_name)
|
super().__init__(dev_id, dev_name)
|
||||||
self._light = None
|
self._light = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user