Remove deprecated unit configuration option from integration integration (#69157)

This commit is contained in:
Diogo Gomes
2022-04-13 18:19:34 +01:00
committed by GitHub
parent 77efe385b7
commit fa28ee1f14
2 changed files with 40 additions and 19 deletions

View File

@@ -4,8 +4,10 @@ from unittest.mock import patch
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
POWER_KILO_WATT,
POWER_WATT,
STATE_UNKNOWN,
TIME_SECONDS,
@@ -24,7 +26,6 @@ async def test_state(hass) -> None:
"platform": "integration",
"name": "integration",
"source": "sensor.power",
"unit": ENERGY_KILO_WATT_HOUR,
"round": 2,
}
}
@@ -34,7 +35,7 @@ async def test_state(hass) -> None:
assert await async_setup_component(hass, "sensor", config)
entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 1, {})
hass.states.async_set(entity_id, 1, {ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT})
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")
@@ -45,7 +46,13 @@ async def test_state(hass) -> None:
future_now = dt_util.utcnow() + timedelta(seconds=3600)
with patch("homeassistant.util.dt.utcnow", return_value=future_now):
hass.states.async_set(
entity_id, 1, {"device_class": SensorDeviceClass.POWER}, force_update=True
entity_id,
1,
{
"device_class": SensorDeviceClass.POWER,
ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT,
},
force_update=True,
)
await hass.async_block_till_done()
@@ -137,7 +144,6 @@ async def test_trapezoidal(hass):
"platform": "integration",
"name": "integration",
"source": "sensor.power",
"unit": ENERGY_KILO_WATT_HOUR,
"round": 2,
}
}
@@ -152,7 +158,12 @@ async def test_trapezoidal(hass):
for time, value in [(20, 10), (30, 30), (40, 5), (50, 0)]:
now = dt_util.utcnow() + timedelta(minutes=time)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(entity_id, value, {}, force_update=True)
hass.states.async_set(
entity_id,
value,
{ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT},
force_update=True,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")
@@ -171,7 +182,6 @@ async def test_left(hass):
"name": "integration",
"method": "left",
"source": "sensor.power",
"unit": ENERGY_KILO_WATT_HOUR,
"round": 2,
}
}
@@ -179,14 +189,19 @@ async def test_left(hass):
assert await async_setup_component(hass, "sensor", config)
entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 0, {})
hass.states.async_set(entity_id, 0, {ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT})
await hass.async_block_till_done()
# Testing a power sensor with non-monotonic intervals and values
for time, value in [(20, 10), (30, 30), (40, 5), (50, 0)]:
now = dt_util.utcnow() + timedelta(minutes=time)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(entity_id, value, {}, force_update=True)
hass.states.async_set(
entity_id,
value,
{ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT},
force_update=True,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")
@@ -205,7 +220,6 @@ async def test_right(hass):
"name": "integration",
"method": "right",
"source": "sensor.power",
"unit": ENERGY_KILO_WATT_HOUR,
"round": 2,
}
}
@@ -213,14 +227,19 @@ async def test_right(hass):
assert await async_setup_component(hass, "sensor", config)
entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 0, {})
hass.states.async_set(entity_id, 0, {ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT})
await hass.async_block_till_done()
# Testing a power sensor with non-monotonic intervals and values
for time, value in [(20, 10), (30, 30), (40, 5), (50, 0)]:
now = dt_util.utcnow() + timedelta(minutes=time)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(entity_id, value, {}, force_update=True)
hass.states.async_set(
entity_id,
value,
{ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT},
force_update=True,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")
@@ -280,12 +299,17 @@ async def test_suffix(hass):
assert await async_setup_component(hass, "sensor", config)
entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 1000, {})
hass.states.async_set(entity_id, 1000, {ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT})
await hass.async_block_till_done()
now = dt_util.utcnow() + timedelta(seconds=10)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(entity_id, 1000, {}, force_update=True)
hass.states.async_set(
entity_id,
1000,
{ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT},
force_update=True,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")