From 8a9edea2c126f6dad12f93ffbdb898ab0cf5a2aa Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 13 Sep 2022 03:24:49 +0200 Subject: [PATCH] Fix calculating gas cost for gas measured in ft3 (#78327) --- homeassistant/components/energy/sensor.py | 3 ++- tests/components/energy/test_sensor.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/energy/sensor.py b/homeassistant/components/energy/sensor.py index 4002f6c416d..602fc09f602 100644 --- a/homeassistant/components/energy/sensor.py +++ b/homeassistant/components/energy/sensor.py @@ -20,6 +20,7 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, ENERGY_MEGA_WATT_HOUR, ENERGY_WATT_HOUR, + VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS, ) from homeassistant.core import ( @@ -44,7 +45,7 @@ SUPPORTED_STATE_CLASSES = [ SensorStateClass.TOTAL_INCREASING, ] VALID_ENERGY_UNITS = [ENERGY_WATT_HOUR, ENERGY_KILO_WATT_HOUR, ENERGY_MEGA_WATT_HOUR] -VALID_ENERGY_UNITS_GAS = [VOLUME_CUBIC_METERS] + VALID_ENERGY_UNITS +VALID_ENERGY_UNITS_GAS = [VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS] + VALID_ENERGY_UNITS _LOGGER = logging.getLogger(__name__) diff --git a/tests/components/energy/test_sensor.py b/tests/components/energy/test_sensor.py index 997f60a8899..9fa82ead2a1 100644 --- a/tests/components/energy/test_sensor.py +++ b/tests/components/energy/test_sensor.py @@ -20,6 +20,7 @@ from homeassistant.const import ( ENERGY_MEGA_WATT_HOUR, ENERGY_WATT_HOUR, STATE_UNKNOWN, + VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS, ) from homeassistant.helpers import entity_registry as er @@ -841,10 +842,13 @@ async def test_cost_sensor_handle_price_units( assert state.state == "20.0" -async def test_cost_sensor_handle_gas(hass, hass_storage, setup_integration) -> None: +@pytest.mark.parametrize("unit", (VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS)) +async def test_cost_sensor_handle_gas( + hass, hass_storage, setup_integration, unit +) -> None: """Test gas cost price from sensor entity.""" energy_attributes = { - ATTR_UNIT_OF_MEASUREMENT: VOLUME_CUBIC_METERS, + ATTR_UNIT_OF_MEASUREMENT: unit, ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING, } energy_data = data.EnergyManager.default_preferences()