mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Remove code slated for deletion in integral (#119935)
* Remove code slated for deletion in integral
This commit is contained in:
parent
60e64d14af
commit
ef51fc0d97
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from decimal import Decimal, DecimalException, InvalidOperation
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from enum import Enum
|
||||
import logging
|
||||
from typing import Any, Final, Self
|
||||
@ -27,7 +27,6 @@ from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_UNIQUE_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import (
|
||||
@ -428,24 +427,6 @@ class IntegrationSensor(RestoreSensor):
|
||||
self._state,
|
||||
self._last_valid_state,
|
||||
)
|
||||
elif (state := await self.async_get_last_state()) is not None:
|
||||
# legacy to be removed on 2023.10 (we are keeping this to avoid losing data during the transition)
|
||||
if state.state in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
||||
if state.state == STATE_UNAVAILABLE:
|
||||
self._attr_available = False
|
||||
else:
|
||||
try:
|
||||
self._state = Decimal(state.state)
|
||||
except (DecimalException, ValueError) as err:
|
||||
_LOGGER.warning(
|
||||
"%s could not restore last state %s: %s",
|
||||
self.entity_id,
|
||||
state.state,
|
||||
err,
|
||||
)
|
||||
|
||||
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
|
||||
if self._max_sub_interval is not None:
|
||||
source_state = self.hass.states.get(self._sensor_source_id)
|
||||
|
@ -30,7 +30,6 @@ import homeassistant.util.dt as dt_util
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_fire_time_changed,
|
||||
mock_restore_cache,
|
||||
mock_restore_cache_with_extra_data,
|
||||
)
|
||||
|
||||
@ -146,42 +145,6 @@ async def test_state(hass: HomeAssistant, method) -> None:
|
||||
|
||||
|
||||
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||
"""Test integration sensor state is restored correctly."""
|
||||
mock_restore_cache(
|
||||
hass,
|
||||
(
|
||||
State(
|
||||
"sensor.integration",
|
||||
"100.0",
|
||||
{
|
||||
"device_class": SensorDeviceClass.ENERGY,
|
||||
"unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR,
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "integration",
|
||||
"name": "integration",
|
||||
"source": "sensor.power",
|
||||
"round": 2,
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, "sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.integration")
|
||||
assert state
|
||||
assert state.state == "100.00"
|
||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes.get("device_class") == SensorDeviceClass.ENERGY
|
||||
assert state.attributes.get("last_good_state") is None
|
||||
|
||||
|
||||
async def test_restore_unavailable_state(hass: HomeAssistant) -> None:
|
||||
"""Test integration sensor state is restored correctly."""
|
||||
mock_restore_cache_with_extra_data(
|
||||
hass,
|
||||
@ -237,9 +200,7 @@ async def test_restore_unavailable_state(hass: HomeAssistant) -> None:
|
||||
},
|
||||
],
|
||||
)
|
||||
async def test_restore_unavailable_state_failed(
|
||||
hass: HomeAssistant, extra_attributes
|
||||
) -> None:
|
||||
async def test_restore_state_failed(hass: HomeAssistant, extra_attributes) -> None:
|
||||
"""Test integration sensor state is restored correctly."""
|
||||
mock_restore_cache_with_extra_data(
|
||||
hass,
|
||||
@ -271,42 +232,7 @@ async def test_restore_unavailable_state_failed(
|
||||
|
||||
state = hass.states.get("sensor.integration")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_restore_state_failed(hass: HomeAssistant) -> None:
|
||||
"""Test integration sensor state is restored correctly."""
|
||||
mock_restore_cache(
|
||||
hass,
|
||||
(
|
||||
State(
|
||||
"sensor.integration",
|
||||
"INVALID",
|
||||
{
|
||||
"last_reset": "2019-10-06T21:00:00.000000",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "integration",
|
||||
"name": "integration",
|
||||
"source": "sensor.power",
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, "sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.integration")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("unit_of_measurement") is None
|
||||
assert state.attributes.get("state_class") is SensorStateClass.TOTAL
|
||||
|
||||
assert "device_class" not in state.attributes
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_trapezoidal(hass: HomeAssistant) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user