mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fixes and code cleanup for IronOS integration (#133579)
* Fix typing and cleanup in IronOS integration * fix test not using freezer * changes * fix timedelta
This commit is contained in:
parent
3d20c5c5d6
commit
26212798a3
@ -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,
|
||||
|
@ -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."""
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user