mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +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 __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.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import MANUFACTURER, MODEL
|
from .const import MANUFACTURER, MODEL
|
||||||
from .coordinator import IronOSBaseCoordinator
|
from .coordinator import IronOSLiveDataCoordinator
|
||||||
|
|
||||||
|
|
||||||
class IronOSBaseEntity(CoordinatorEntity[IronOSBaseCoordinator]):
|
class IronOSBaseEntity(CoordinatorEntity[IronOSLiveDataCoordinator]):
|
||||||
"""Base IronOS entity."""
|
"""Base IronOS entity."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: IronOSBaseCoordinator,
|
coordinator: IronOSLiveDataCoordinator,
|
||||||
entity_description: EntityDescription,
|
entity_description: EntityDescription,
|
||||||
context: Any | None = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator, context=context)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
@ -32,7 +31,8 @@ class IronOSBaseEntity(CoordinatorEntity[IronOSBaseCoordinator]):
|
|||||||
)
|
)
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert coordinator.config_entry.unique_id
|
assert coordinator.config_entry.unique_id
|
||||||
self.device_info = DeviceInfo(
|
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
connections={(CONNECTION_BLUETOOTH, coordinator.config_entry.unique_id)},
|
connections={(CONNECTION_BLUETOOTH, coordinator.config_entry.unique_id)},
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
model=MODEL,
|
model=MODEL,
|
||||||
|
@ -336,10 +336,10 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up number entities from a config entry."""
|
"""Set up number entities from a config entry."""
|
||||||
coordinator = entry.runtime_data
|
coordinators = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
IronOSNumberEntity(coordinator, description)
|
IronOSNumberEntity(coordinators, description)
|
||||||
for description in PINECIL_NUMBER_DESCRIPTIONS
|
for description in PINECIL_NUMBER_DESCRIPTIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -351,15 +351,13 @@ class IronOSNumberEntity(IronOSBaseEntity, NumberEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: IronOSCoordinators,
|
coordinators: IronOSCoordinators,
|
||||||
entity_description: IronOSNumberEntityDescription,
|
entity_description: IronOSNumberEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the number entity."""
|
"""Initialize the number entity."""
|
||||||
super().__init__(
|
super().__init__(coordinators.live_data, entity_description)
|
||||||
coordinator.live_data, entity_description, entity_description.characteristic
|
|
||||||
)
|
|
||||||
|
|
||||||
self.settings = coordinator.settings
|
self.settings = coordinators.settings
|
||||||
|
|
||||||
async def async_set_native_value(self, value: float) -> None:
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
"""Update the current value."""
|
"""Update the current value."""
|
||||||
|
@ -164,15 +164,13 @@ class IronOSSelectEntity(IronOSBaseEntity, SelectEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: IronOSCoordinators,
|
coordinators: IronOSCoordinators,
|
||||||
entity_description: IronOSSelectEntityDescription,
|
entity_description: IronOSSelectEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the select entity."""
|
"""Initialize the select entity."""
|
||||||
super().__init__(
|
super().__init__(coordinators.live_data, entity_description)
|
||||||
coordinator.live_data, entity_description, entity_description.characteristic
|
|
||||||
)
|
|
||||||
|
|
||||||
self.settings = coordinator.settings
|
self.settings = coordinators.settings
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_option(self) -> str | None:
|
def current_option(self) -> str | None:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Test init of IronOS integration."""
|
"""Test init of IronOS integration."""
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
@ -73,6 +73,7 @@ async def test_settings_exception(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
mock_pynecil: AsyncMock,
|
mock_pynecil: AsyncMock,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test skipping of settings on exception."""
|
"""Test skipping of settings on exception."""
|
||||||
mock_pynecil.get_settings.side_effect = CommunicationError
|
mock_pynecil.get_settings.side_effect = CommunicationError
|
||||||
@ -80,7 +81,8 @@ async def test_settings_exception(
|
|||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert config_entry.state is ConfigEntryState.LOADED
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user