Skip to content

Commit

Permalink
Improve init type hints in enocean (#92176)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Apr 28, 2023
1 parent 8c64eda commit 67a7de1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
14 changes: 10 additions & 4 deletions homeassistant/components/enocean/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.components.binary_sensor import (
DEVICE_CLASSES_SCHEMA,
PLATFORM_SCHEMA,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import CONF_DEVICE_CLASS, CONF_ID, CONF_NAME
Expand Down Expand Up @@ -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)])

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/enocean/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/enocean/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])

Expand All @@ -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
Expand Down
31 changes: 17 additions & 14 deletions homeassistant/components/enocean/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/enocean/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand All @@ -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
Expand Down

0 comments on commit 67a7de1

Please sign in to comment.