From 21cf5dc3213cf5a3556e5017ce2a51ebea4e754a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 19 Feb 2026 14:30:27 +0100 Subject: [PATCH] Use shorthand attribute in elv switch (#163488) --- homeassistant/components/elv/switch.py | 29 +++++--------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/elv/switch.py b/homeassistant/components/elv/switch.py index e790873e368..c4645dc39b3 100644 --- a/homeassistant/components/elv/switch.py +++ b/homeassistant/components/elv/switch.py @@ -16,8 +16,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType _LOGGER = logging.getLogger(__name__) -DEFAULT_NAME = "PCA 301" - def setup_platform( hass: HomeAssistant, @@ -54,26 +52,9 @@ class SmartPlugSwitch(SwitchEntity): def __init__(self, pca, device_id): """Initialize the switch.""" self._device_id = device_id - self._name = "PCA 301" - self._state = None - self._available = True + self._attr_name = "PCA 301" self._pca = pca - @property - def name(self): - """Return the name of the Smart Plug, if any.""" - return self._name - - @property - def available(self) -> bool: - """Return if switch is available.""" - return self._available - - @property - def is_on(self): - """Return true if switch is on.""" - return self._state - def turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" self._pca.turn_on(self._device_id) @@ -85,10 +66,10 @@ class SmartPlugSwitch(SwitchEntity): def update(self) -> None: """Update the PCA switch's state.""" try: - self._state = self._pca.get_state(self._device_id) - self._available = True + self._attr_is_on = self._pca.get_state(self._device_id) + self._attr_available = True except OSError as ex: - if self._available: + if self._attr_available: _LOGGER.warning("Could not read state for %s: %s", self.name, ex) - self._available = False + self._attr_available = False