diff --git a/homeassistant/components/lutron/__init__.py b/homeassistant/components/lutron/__init__.py index b5b7f4d1b31c..d89797eedc71 100644 --- a/homeassistant/components/lutron/__init__.py +++ b/homeassistant/components/lutron/__init__.py @@ -2,7 +2,7 @@ from dataclasses import dataclass import logging -from pylutron import Button, Led, Lutron, OccupancyGroup, Output +from pylutron import Button, Keypad, Led, Lutron, LutronEvent, OccupancyGroup, Output import voluptuous as vol from homeassistant import config_entries @@ -110,7 +110,9 @@ class LutronButton: represented as an entity; it simply fires events. """ - def __init__(self, hass: HomeAssistant, area_name, keypad, button) -> None: + def __init__( + self, hass: HomeAssistant, area_name: str, keypad: Keypad, button: Button + ) -> None: """Register callback for activity on the button.""" name = f"{keypad.name}: {button.name}" if button.name == "Unknown Button": @@ -130,7 +132,9 @@ class LutronButton: button.subscribe(self.button_callback, None) - def button_callback(self, button, context, event, params): + def button_callback( + self, _button: Button, _context: None, event: LutronEvent, _params: dict + ) -> None: """Fire an event about a button being pressed or released.""" # Events per button type: # RaiseLower -> pressed/released @@ -154,17 +158,17 @@ class LutronButton: self._hass.bus.fire(self._event, data) -@dataclass(slots=True) +@dataclass(slots=True, kw_only=True) class LutronData: """Storage class for platform global data.""" client: Lutron - covers: list[tuple[str, Output]] - lights: list[tuple[str, Output]] - switches: list[tuple[str, Output]] - scenes: list[tuple[str, str, Button, Led]] binary_sensors: list[tuple[str, OccupancyGroup]] buttons: list[LutronButton] + covers: list[tuple[str, Output]] + lights: list[tuple[str, Output]] + scenes: list[tuple[str, str, Button, Led]] + switches: list[tuple[str, Output]] async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: @@ -181,12 +185,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b entry_data = LutronData( client=lutron_client, - covers=[], - lights=[], - switches=[], - scenes=[], binary_sensors=[], buttons=[], + covers=[], + lights=[], + scenes=[], + switches=[], ) # Sort our devices into types _LOGGER.debug("Start adding devices") diff --git a/homeassistant/components/lutron/binary_sensor.py b/homeassistant/components/lutron/binary_sensor.py index 65f9bd4d3900..8433724d4895 100644 --- a/homeassistant/components/lutron/binary_sensor.py +++ b/homeassistant/components/lutron/binary_sensor.py @@ -49,6 +49,7 @@ class LutronOccupancySensor(LutronDevice, BinarySensorEntity): reported as a single occupancy group. """ + _lutron_device: OccupancyGroup _attr_device_class = BinarySensorDeviceClass.OCCUPANCY @property diff --git a/homeassistant/components/lutron/cover.py b/homeassistant/components/lutron/cover.py index 1658d92b79c0..1941c050aa49 100644 --- a/homeassistant/components/lutron/cover.py +++ b/homeassistant/components/lutron/cover.py @@ -5,6 +5,8 @@ from collections.abc import Mapping import logging from typing import Any +from pylutron import Output + from homeassistant.components.cover import ( ATTR_POSITION, CoverEntity, @@ -33,7 +35,7 @@ async def async_setup_entry( entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id] async_add_entities( [ - LutronCover(area_name, device, entry_data.covers) + LutronCover(area_name, device, entry_data.client) for area_name, device in entry_data.covers ], True, @@ -48,6 +50,7 @@ class LutronCover(LutronDevice, CoverEntity): | CoverEntityFeature.CLOSE | CoverEntityFeature.SET_POSITION ) + _lutron_device: Output @property def is_closed(self) -> bool: diff --git a/homeassistant/components/lutron/entity.py b/homeassistant/components/lutron/entity.py index 238c2e3c5529..423186eceae0 100644 --- a/homeassistant/components/lutron/entity.py +++ b/homeassistant/components/lutron/entity.py @@ -1,4 +1,7 @@ """Base class for Lutron devices.""" + +from pylutron import Lutron, LutronEntity, LutronEvent + from homeassistant.helpers.entity import Entity @@ -7,7 +10,9 @@ class LutronDevice(Entity): _attr_should_poll = False - def __init__(self, area_name, lutron_device, controller) -> None: + def __init__( + self, area_name: str, lutron_device: LutronEntity, controller: Lutron + ) -> None: """Initialize the device.""" self._lutron_device = lutron_device self._controller = controller @@ -17,7 +22,9 @@ class LutronDevice(Entity): """Register callbacks.""" self._lutron_device.subscribe(self._update_callback, None) - def _update_callback(self, _device, _context, _event, _params): + def _update_callback( + self, _device: LutronEntity, _context: None, _event: LutronEvent, _params: dict + ) -> None: """Run when invoked by pylutron when the device state changes.""" self.schedule_update_ha_state() @@ -27,7 +34,7 @@ class LutronDevice(Entity): return f"{self._area_name} {self._lutron_device.name}" @property - def unique_id(self): + def unique_id(self) -> str | None: """Return a unique ID.""" # Temporary fix for https://github.com/thecynic/pylutron/issues/70 if self._lutron_device.uuid is None: diff --git a/homeassistant/components/lutron/light.py b/homeassistant/components/lutron/light.py index a04006de61f5..b6860a4e8182 100644 --- a/homeassistant/components/lutron/light.py +++ b/homeassistant/components/lutron/light.py @@ -4,6 +4,8 @@ from __future__ import annotations from collections.abc import Mapping from typing import Any +from pylutron import Output + from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -48,11 +50,8 @@ class LutronLight(LutronDevice, LightEntity): _attr_color_mode = ColorMode.BRIGHTNESS _attr_supported_color_modes = {ColorMode.BRIGHTNESS} - - def __init__(self, area_name, lutron_device, controller) -> None: - """Initialize the light.""" - self._prev_brightness = None - super().__init__(area_name, lutron_device, controller) + _lutron_device: Output + _prev_brightness: int | None = None @property def brightness(self) -> int: diff --git a/homeassistant/components/lutron/scene.py b/homeassistant/components/lutron/scene.py index 2033a9024bfd..ae8f787d290b 100644 --- a/homeassistant/components/lutron/scene.py +++ b/homeassistant/components/lutron/scene.py @@ -3,6 +3,8 @@ from __future__ import annotations from typing import Any +from pylutron import Button, Led, Lutron + from homeassistant.components.scene import Scene from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -36,7 +38,16 @@ async def async_setup_entry( class LutronScene(LutronDevice, Scene): """Representation of a Lutron Scene.""" - def __init__(self, area_name, keypad_name, lutron_device, lutron_led, controller): + _lutron_device: Button + + def __init__( + self, + area_name: str, + keypad_name: str, + lutron_device: Button, + lutron_led: Led, + controller: Lutron, + ) -> None: """Initialize the scene/button.""" super().__init__(area_name, lutron_device, controller) self._keypad_name = keypad_name diff --git a/homeassistant/components/lutron/switch.py b/homeassistant/components/lutron/switch.py index b418c9c481c1..5cb7dcf53d83 100644 --- a/homeassistant/components/lutron/switch.py +++ b/homeassistant/components/lutron/switch.py @@ -4,6 +4,8 @@ from __future__ import annotations from collections.abc import Mapping from typing import Any +from pylutron import Button, Led, Lutron, Output + from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -42,7 +44,11 @@ async def async_setup_entry( class LutronSwitch(LutronDevice, SwitchEntity): """Representation of a Lutron Switch.""" - def __init__(self, area_name, lutron_device, controller) -> None: + _lutron_device: Output + + def __init__( + self, area_name: str, lutron_device: Output, controller: Lutron + ) -> None: """Initialize the switch.""" self._prev_state = None super().__init__(area_name, lutron_device, controller) @@ -74,7 +80,16 @@ class LutronSwitch(LutronDevice, SwitchEntity): class LutronLed(LutronDevice, SwitchEntity): """Representation of a Lutron Keypad LED.""" - def __init__(self, area_name, keypad_name, scene_device, led_device, controller): + _lutron_device: Led + + def __init__( + self, + area_name: str, + keypad_name: str, + scene_device: Button, + led_device: Led, + controller: Lutron, + ) -> None: """Initialize the switch.""" self._keypad_name = keypad_name self._scene_name = scene_device.name