Add and use more unit constants (#32122)
* Add and use speed constants * Add and use meter based volume and area constants * Add and use more mass unit constants * Add and use concentration unit constants * Add and use watts per square meter constant * Use more time constants * Use more data constants
This commit is contained in:
1 parent
c98f50115d
commit
496bd3dddf
44 files changed
+422
-177
No files matched your search
@@ -15,7 +15,7 @@ import pytest
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.dsmr.sensor import DerivativeDSMREntity
|
||||
from homeassistant.const import TIME_HOURS
|
||||
from homeassistant.const import TIME_HOURS, VOLUME_CUBIC_METERS
|
||||
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
@@ -67,7 +67,7 @@ async def test_default_setup(hass, mock_connection_factory):
|
||||
GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
}
|
||||
@@ -101,7 +101,7 @@ async def test_default_setup(hass, mock_connection_factory):
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_derivative():
|
||||
@@ -119,7 +119,7 @@ async def test_derivative():
|
||||
"1.0.0": MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ async def test_derivative():
|
||||
"1.0.0": MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642543)},
|
||||
{"value": Decimal(745.698), "unit": "m3"},
|
||||
{"value": Decimal(745.698), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -141,7 +141,7 @@ async def test_derivative():
|
||||
abs(entity.state - 0.033) < 0.00001
|
||||
), "state should be hourly usage calculated from first and second update"
|
||||
|
||||
assert entity.unit_of_measurement == f"m3/{TIME_HOURS}"
|
||||
assert entity.unit_of_measurement == f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}"
|
||||
|
||||
|
||||
async def test_v4_meter(hass, mock_connection_factory):
|
||||
@@ -160,7 +160,7 @@ async def test_v4_meter(hass, mock_connection_factory):
|
||||
HOURLY_GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]),
|
||||
@@ -185,7 +185,7 @@ async def test_v4_meter(hass, mock_connection_factory):
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_belgian_meter(hass, mock_connection_factory):
|
||||
@@ -204,7 +204,7 @@ async def test_belgian_meter(hass, mock_connection_factory):
|
||||
BELGIUM_HOURLY_GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]),
|
||||
@@ -229,7 +229,7 @@ async def test_belgian_meter(hass, mock_connection_factory):
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_belgian_meter_low(hass, mock_connection_factory):
|
||||
|
||||
Reference in new issue
Block a user