Cleanup of HomeWizard button platform (#85999)

This commit is contained in:
Franck Nijhof 2023-01-16 11:57:08 +01:00 committed by GitHub
parent 13cfd60019
commit 2b037efee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 14 deletions

View File

@ -1,7 +1,4 @@
"""Support for HomeWizard buttons.""" """Support for HomeWizard buttons."""
import logging
from homeassistant.components.button import ButtonEntity from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -13,23 +10,23 @@ from .coordinator import HWEnergyDeviceUpdateCoordinator
from .entity import HomeWizardEntity from .entity import HomeWizardEntity
from .helpers import homewizard_exception_handler from .helpers import homewizard_exception_handler
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up the Identify button.""" """Set up the Identify button."""
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
if coordinator.data.features.has_identify:
features = await coordinator.api.features()
if features.has_identify:
async_add_entities([HomeWizardIdentifyButton(coordinator, entry)]) async_add_entities([HomeWizardIdentifyButton(coordinator, entry)])
class HomeWizardIdentifyButton(HomeWizardEntity, ButtonEntity): class HomeWizardIdentifyButton(HomeWizardEntity, ButtonEntity):
"""Representation of a identify button.""" """Representation of a identify button."""
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:magnify"
_attr_name = "Identify"
def __init__( def __init__(
self, self,
coordinator: HWEnergyDeviceUpdateCoordinator, coordinator: HWEnergyDeviceUpdateCoordinator,
@ -38,9 +35,6 @@ class HomeWizardIdentifyButton(HomeWizardEntity, ButtonEntity):
"""Initialize button.""" """Initialize button."""
super().__init__(coordinator) super().__init__(coordinator)
self._attr_unique_id = f"{entry.unique_id}_identify" 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 @homewizard_exception_handler
async def async_press(self) -> None: async def async_press(self) -> None:

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from datetime import timedelta from datetime import timedelta
# Set up. from homewizard_energy.features import Features
from homewizard_energy.models import Data, Device, State, System from homewizard_energy.models import Data, Device, State, System
from homeassistant.const import Platform from homeassistant.const import Platform
@ -30,5 +30,6 @@ class DeviceResponseEntry:
device: Device device: Device
data: Data data: Data
features: Features
state: State | None state: State | None
system: System | None = None system: System | None = None

View File

@ -42,11 +42,11 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
data = DeviceResponseEntry( data = DeviceResponseEntry(
device=await self.api.device(), device=await self.api.device(),
data=await self.api.data(), data=await self.api.data(),
features=await self.api.features(),
state=await self.api.state(), state=await self.api.state(),
) )
features = await self.api.features() if data.features.has_system:
if features.has_system:
data.system = await self.api.system() data.system = await self.api.system()
except RequestError as ex: except RequestError as ex: