From 2b037efee27c0f4a63baabffafa30bf54f3e2870 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 16 Jan 2023 11:57:08 +0100 Subject: [PATCH] Cleanup of HomeWizard button platform (#85999) --- homeassistant/components/homewizard/button.py | 16 +++++----------- homeassistant/components/homewizard/const.py | 3 ++- .../components/homewizard/coordinator.py | 4 ++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/homewizard/button.py b/homeassistant/components/homewizard/button.py index 6523ae705c1..00fd3c38ef9 100644 --- a/homeassistant/components/homewizard/button.py +++ b/homeassistant/components/homewizard/button.py @@ -1,7 +1,4 @@ """Support for HomeWizard buttons.""" - -import logging - from homeassistant.components.button import ButtonEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -13,23 +10,23 @@ from .coordinator import HWEnergyDeviceUpdateCoordinator from .entity import HomeWizardEntity from .helpers import homewizard_exception_handler -_LOGGER = logging.getLogger(__name__) - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up the Identify button.""" coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - - features = await coordinator.api.features() - if features.has_identify: + if coordinator.data.features.has_identify: async_add_entities([HomeWizardIdentifyButton(coordinator, entry)]) class HomeWizardIdentifyButton(HomeWizardEntity, ButtonEntity): """Representation of a identify button.""" + _attr_entity_category = EntityCategory.DIAGNOSTIC + _attr_icon = "mdi:magnify" + _attr_name = "Identify" + def __init__( self, coordinator: HWEnergyDeviceUpdateCoordinator, @@ -38,9 +35,6 @@ class HomeWizardIdentifyButton(HomeWizardEntity, ButtonEntity): """Initialize button.""" super().__init__(coordinator) self._attr_unique_id = f"{entry.unique_id}_identify" - self._attr_name = "Identify" - self._attr_icon = "mdi:magnify" - self._attr_entity_category = EntityCategory.DIAGNOSTIC @homewizard_exception_handler async def async_press(self) -> None: diff --git a/homeassistant/components/homewizard/const.py b/homeassistant/components/homewizard/const.py index 7627d48accb..34c83626f86 100644 --- a/homeassistant/components/homewizard/const.py +++ b/homeassistant/components/homewizard/const.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass from datetime import timedelta -# Set up. +from homewizard_energy.features import Features from homewizard_energy.models import Data, Device, State, System from homeassistant.const import Platform @@ -30,5 +30,6 @@ class DeviceResponseEntry: device: Device data: Data + features: Features state: State | None system: System | None = None diff --git a/homeassistant/components/homewizard/coordinator.py b/homeassistant/components/homewizard/coordinator.py index f49f7f8ccdc..4f003da32bb 100644 --- a/homeassistant/components/homewizard/coordinator.py +++ b/homeassistant/components/homewizard/coordinator.py @@ -42,11 +42,11 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry] data = DeviceResponseEntry( device=await self.api.device(), data=await self.api.data(), + features=await self.api.features(), state=await self.api.state(), ) - features = await self.api.features() - if features.has_system: + if data.features.has_system: data.system = await self.api.system() except RequestError as ex: