Use POWER_WATT constant (#33984)

This commit is contained in:
springstan authored and GitHub committed 2020-04-11 15:40:59 +02:00
1 parent 2ab79115d1
commit f839ba00eb
14 files changed
+56 -35

No files matched your search

+3 -3
View File
@@ -2,7 +2,7 @@
from datetime import timedelta
from unittest.mock import patch
from homeassistant.const import TIME_HOURS, TIME_MINUTES, TIME_SECONDS
from homeassistant.const import POWER_WATT, TIME_HOURS, TIME_MINUTES, TIME_SECONDS
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -192,14 +192,14 @@ async def test_prefix(hass):
entity_id = config["sensor"]["source"]
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()
now = dt_util.utcnow() + timedelta(seconds=3600)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()
@@ -310,7 +310,7 @@ async def test_hmip_windspeed_sensor(hass, default_mock_hap_factory):
205: "SSW",
227.5: "SW",
250: "WSW",
272.5: "W",
272.5: POWER_WATT,
295: "WNW",
317.5: "NW",
340: "NNW",
+3 -3
View File
@@ -2,7 +2,7 @@
from datetime import timedelta
from unittest.mock import patch
from homeassistant.const import ENERGY_KILO_WATT_HOUR, TIME_SECONDS
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, TIME_SECONDS
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@@ -155,13 +155,13 @@ async def test_prefix(hass):
assert await async_setup_component(hass, "sensor", config)
entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 1000, {"unit_of_measurement": "W"})
hass.states.async_set(entity_id, 1000, {"unit_of_measurement": POWER_WATT})
await hass.async_block_till_done()
now = dt_util.utcnow() + timedelta(seconds=3600)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()
+5 -4
View File
@@ -14,6 +14,7 @@ from homeassistant.const import (
CONF_UNIT_SYSTEM,
CONF_UNIT_SYSTEM_IMPERIAL,
CONF_UNIT_SYSTEM_METRIC,
POWER_WATT,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
TEMP_CELSIUS,
@@ -76,17 +77,17 @@ async def async_test_electrical_measurement(hass, cluster, entity_id):
) as divisor_mock:
divisor_mock.return_value = 1
await send_attributes_report(hass, cluster, {0: 1, 1291: 100, 10: 1000})
assert_state(hass, entity_id, "100", "W")
assert_state(hass, entity_id, "100", POWER_WATT)
await send_attributes_report(hass, cluster, {0: 1, 1291: 99, 10: 1000})
assert_state(hass, entity_id, "99", "W")
assert_state(hass, entity_id, "99", POWER_WATT)
divisor_mock.return_value = 10
await send_attributes_report(hass, cluster, {0: 1, 1291: 1000, 10: 5000})
assert_state(hass, entity_id, "100", "W")
assert_state(hass, entity_id, "100", POWER_WATT)
await send_attributes_report(hass, cluster, {0: 1, 1291: 99, 10: 5000})
assert_state(hass, entity_id, "9.9", "W")
assert_state(hass, entity_id, "9.9", POWER_WATT)
@pytest.mark.parametrize(