mirror of
https://github.com/home-assistant/core.git
synced 2026-07-04 23:51:32 +02:00
Fix Acaia battery sensor going unavailable on first-session disconnect (#169420)
Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
@@ -143,4 +143,4 @@ class AcaiaRestoreSensor(AcaiaEntity, RestoreSensor):
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return super().available or self._restored_data is not None
|
||||
return super().available or self.native_value is not None
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"""Test sensors for acaia integration."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import PERCENTAGE, Platform
|
||||
@@ -12,6 +14,7 @@ from . import setup_integration
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_fire_time_changed,
|
||||
mock_restore_cache_with_extra_data,
|
||||
snapshot_platform,
|
||||
)
|
||||
@@ -61,3 +64,28 @@ async def test_restore_state(
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == "65"
|
||||
|
||||
|
||||
async def test_battery_available_within_session_after_disconnect(
|
||||
hass: HomeAssistant,
|
||||
mock_scale: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test battery stays available on disconnect when no restore data exists."""
|
||||
entity_id = "sensor.lunar_ddeeff_battery"
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == "42"
|
||||
|
||||
mock_scale.connected = False
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == "42"
|
||||
|
||||
Reference in New Issue
Block a user