Skip to content

Commit

Permalink
Fixes and code cleanup for IronOS integration (#133579)
Browse files Browse the repository at this point in the history
* Fix typing and cleanup in IronOS integration

* fix test not using freezer

* changes

* fix timedelta
  • Loading branch information
tr4nt0r authored Dec 20, 2024
1 parent 3d20c5c commit 2621279
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
14 changes: 7 additions & 7 deletions homeassistant/components/iron_os/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

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 = (
f"{coordinator.config_entry.unique_id}_{entity_description.key}"
)
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,
Expand Down
12 changes: 5 additions & 7 deletions homeassistant/components/iron_os/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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."""
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/iron_os/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions tests/components/iron_os/test_init.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -73,14 +73,16 @@ 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

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
Expand Down

0 comments on commit 2621279

Please sign in to comment.