From 67a7de18698d893853573cc691baaecdd8939afa Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:14:37 +0200 Subject: [PATCH] Improve init type hints in enocean (#92176) --- .../components/enocean/binary_sensor.py | 14 ++++++--- homeassistant/components/enocean/device.py | 2 +- homeassistant/components/enocean/light.py | 8 ++--- homeassistant/components/enocean/sensor.py | 31 ++++++++++--------- homeassistant/components/enocean/switch.py | 8 ++--- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/enocean/binary_sensor.py b/homeassistant/components/enocean/binary_sensor.py index e18542241da..e7f94647941 100644 --- a/homeassistant/components/enocean/binary_sensor.py +++ b/homeassistant/components/enocean/binary_sensor.py @@ -7,6 +7,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import ( DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import CONF_DEVICE_CLASS, CONF_ID, CONF_NAME @@ -37,9 +38,9 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Binary Sensor platform for EnOcean.""" - dev_id = config.get(CONF_ID) - dev_name = config.get(CONF_NAME) - device_class = config.get(CONF_DEVICE_CLASS) + dev_id: list[int] = config[CONF_ID] + dev_name: str = config[CONF_NAME] + device_class: BinarySensorDeviceClass | None = config.get(CONF_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) """ - 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.""" super().__init__(dev_id, dev_name) self._device_class = device_class diff --git a/homeassistant/components/enocean/device.py b/homeassistant/components/enocean/device.py index 0bd084742b5..1c98b4dd234 100644 --- a/homeassistant/components/enocean/device.py +++ b/homeassistant/components/enocean/device.py @@ -11,7 +11,7 @@ from .const import SIGNAL_RECEIVE_MESSAGE, SIGNAL_SEND_MESSAGE class EnOceanEntity(Entity): """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.""" self.dev_id = dev_id self.dev_name = dev_name diff --git a/homeassistant/components/enocean/light.py b/homeassistant/components/enocean/light.py index 479723bd051..e2a194af8ba 100644 --- a/homeassistant/components/enocean/light.py +++ b/homeassistant/components/enocean/light.py @@ -41,9 +41,9 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the EnOcean light platform.""" - sender_id = config.get(CONF_SENDER_ID) - dev_name = config.get(CONF_NAME) - dev_id = config.get(CONF_ID) + sender_id: list[int] = config[CONF_SENDER_ID] + dev_name: str = config[CONF_NAME] + dev_id: list[int] = config[CONF_ID] add_entities([EnOceanLight(sender_id, dev_id, dev_name)]) @@ -54,7 +54,7 @@ class EnOceanLight(EnOceanEntity, LightEntity): _attr_color_mode = 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.""" super().__init__(dev_id, dev_name) self._on_state = False diff --git a/homeassistant/components/enocean/sensor.py b/homeassistant/components/enocean/sensor.py index ae2110b3174..4fa3b25ed06 100644 --- a/homeassistant/components/enocean/sensor.py +++ b/homeassistant/components/enocean/sensor.py @@ -117,16 +117,16 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up an EnOcean sensor device.""" - dev_id = config[CONF_ID] - dev_name = config[CONF_NAME] - sensor_type = config[CONF_DEVICE_CLASS] + dev_id: list[int] = config[CONF_ID] + dev_name: str = config[CONF_NAME] + sensor_type: str = config[CONF_DEVICE_CLASS] entities: list[EnOceanSensor] = [] if sensor_type == SENSOR_TYPE_TEMPERATURE: - temp_min = config[CONF_MIN_TEMP] - temp_max = config[CONF_MAX_TEMP] - range_from = config[CONF_RANGE_FROM] - range_to = config[CONF_RANGE_TO] + temp_min: int = config[CONF_MIN_TEMP] + temp_max: int = config[CONF_MAX_TEMP] + range_from: int = config[CONF_RANGE_FROM] + range_to: int = config[CONF_RANGE_TO] entities = [ EnOceanTemperatureSensor( dev_id, @@ -155,7 +155,10 @@ class EnOceanSensor(EnOceanEntity, RestoreEntity, SensorEntity): """Representation of an EnOcean sensor device such as a power meter.""" def __init__( - self, dev_id, dev_name, description: EnOceanSensorEntityDescription + self, + dev_id: list[int], + dev_name: str, + description: EnOceanSensorEntityDescription, ) -> None: """Initialize the EnOcean sensor device.""" super().__init__(dev_id, dev_name) @@ -217,14 +220,14 @@ class EnOceanTemperatureSensor(EnOceanSensor): def __init__( self, - dev_id, - dev_name, + dev_id: list[int], + dev_name: str, description: EnOceanSensorEntityDescription, *, - scale_min, - scale_max, - range_from, - range_to, + scale_min: int, + scale_max: int, + range_from: int, + range_to: int, ) -> None: """Initialize the EnOcean temperature sensor device.""" super().__init__(dev_id, dev_name, description) diff --git a/homeassistant/components/enocean/switch.py b/homeassistant/components/enocean/switch.py index 11ca8a2a625..c69821c8372 100644 --- a/homeassistant/components/enocean/switch.py +++ b/homeassistant/components/enocean/switch.py @@ -65,9 +65,9 @@ async def async_setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the EnOcean switch platform.""" - channel = config.get(CONF_CHANNEL) - dev_id = config.get(CONF_ID) - dev_name = config.get(CONF_NAME) + channel: int = config[CONF_CHANNEL] + dev_id: list[int] = config[CONF_ID] + dev_name: str = config[CONF_NAME] _migrate_to_new_unique_id(hass, dev_id, channel) async_add_entities([EnOceanSwitch(dev_id, dev_name, channel)]) @@ -76,7 +76,7 @@ async def async_setup_platform( class EnOceanSwitch(EnOceanEntity, SwitchEntity): """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.""" super().__init__(dev_id, dev_name) self._light = None