From 26212798a334e208a35a0c6dfc0dc495d149fa40 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:25:08 +0100 Subject: [PATCH] Fixes and code cleanup for IronOS integration (#133579) * Fix typing and cleanup in IronOS integration * fix test not using freezer * changes * fix timedelta --- homeassistant/components/iron_os/entity.py | 14 +++++++------- homeassistant/components/iron_os/number.py | 12 +++++------- homeassistant/components/iron_os/select.py | 8 +++----- tests/components/iron_os/test_init.py | 6 ++++-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/iron_os/entity.py b/homeassistant/components/iron_os/entity.py index 684957a2197..190a9f33639 100644 --- a/homeassistant/components/iron_os/entity.py +++ b/homeassistant/components/iron_os/entity.py @@ -2,29 +2,28 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import MANUFACTURER, MODEL -from .coordinator import IronOSBaseCoordinator +from .coordinator import IronOSLiveDataCoordinator -class IronOSBaseEntity(CoordinatorEntity[IronOSBaseCoordinator]): +class IronOSBaseEntity(CoordinatorEntity[IronOSLiveDataCoordinator]): """Base IronOS entity.""" _attr_has_entity_name = True def __init__( self, - coordinator: IronOSBaseCoordinator, + coordinator: IronOSLiveDataCoordinator, entity_description: EntityDescription, - context: Any | None = None, ) -> None: """Initialize the sensor.""" - super().__init__(coordinator, context=context) + super().__init__(coordinator) self.entity_description = entity_description self._attr_unique_id = ( @@ -32,7 +31,8 @@ class IronOSBaseEntity(CoordinatorEntity[IronOSBaseCoordinator]): ) if TYPE_CHECKING: assert coordinator.config_entry.unique_id - self.device_info = DeviceInfo( + + self._attr_device_info = DeviceInfo( connections={(CONNECTION_BLUETOOTH, coordinator.config_entry.unique_id)}, manufacturer=MANUFACTURER, model=MODEL, diff --git a/homeassistant/components/iron_os/number.py b/homeassistant/components/iron_os/number.py index a288a61b021..583844223dd 100644 --- a/homeassistant/components/iron_os/number.py +++ b/homeassistant/components/iron_os/number.py @@ -336,10 +336,10 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up number entities from a config entry.""" - coordinator = entry.runtime_data + coordinators = entry.runtime_data async_add_entities( - IronOSNumberEntity(coordinator, description) + IronOSNumberEntity(coordinators, description) for description in PINECIL_NUMBER_DESCRIPTIONS ) @@ -351,15 +351,13 @@ class IronOSNumberEntity(IronOSBaseEntity, NumberEntity): def __init__( self, - coordinator: IronOSCoordinators, + coordinators: IronOSCoordinators, entity_description: IronOSNumberEntityDescription, ) -> None: """Initialize the number entity.""" - super().__init__( - coordinator.live_data, entity_description, entity_description.characteristic - ) + super().__init__(coordinators.live_data, entity_description) - self.settings = coordinator.settings + self.settings = coordinators.settings async def async_set_native_value(self, value: float) -> None: """Update the current value.""" diff --git a/homeassistant/components/iron_os/select.py b/homeassistant/components/iron_os/select.py index c863e076f0b..10d8a6fcef5 100644 --- a/homeassistant/components/iron_os/select.py +++ b/homeassistant/components/iron_os/select.py @@ -164,15 +164,13 @@ class IronOSSelectEntity(IronOSBaseEntity, SelectEntity): def __init__( self, - coordinator: IronOSCoordinators, + coordinators: IronOSCoordinators, entity_description: IronOSSelectEntityDescription, ) -> None: """Initialize the select entity.""" - super().__init__( - coordinator.live_data, entity_description, entity_description.characteristic - ) + super().__init__(coordinators.live_data, entity_description) - self.settings = coordinator.settings + self.settings = coordinators.settings @property def current_option(self) -> str | None: diff --git a/tests/components/iron_os/test_init.py b/tests/components/iron_os/test_init.py index 21194a55eea..15327c55121 100644 --- a/tests/components/iron_os/test_init.py +++ b/tests/components/iron_os/test_init.py @@ -1,6 +1,6 @@ """Test init of IronOS integration.""" -from datetime import datetime, timedelta +from datetime import timedelta from unittest.mock import AsyncMock from freezegun.api import FrozenDateTimeFactory @@ -73,6 +73,7 @@ async def test_settings_exception( hass: HomeAssistant, config_entry: MockConfigEntry, mock_pynecil: AsyncMock, + freezer: FrozenDateTimeFactory, ) -> None: """Test skipping of settings on exception.""" mock_pynecil.get_settings.side_effect = CommunicationError @@ -80,7 +81,8 @@ async def test_settings_exception( config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - async_fire_time_changed(hass, datetime.now() + timedelta(seconds=60)) + freezer.tick(timedelta(seconds=60)) + async_fire_time_changed(hass) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED