diff --git a/tests/components/flipr/test_sensor.py b/tests/components/flipr/test_sensor.py index 51fbf2941f8..75ab6ffd0bd 100644 --- a/tests/components/flipr/test_sensor.py +++ b/tests/components/flipr/test_sensor.py @@ -12,7 +12,7 @@ from homeassistant.const import ( CONF_EMAIL, CONF_PASSWORD, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as entity_reg @@ -71,7 +71,7 @@ async def test_sensors(hass: HomeAssistant) -> None: state = hass.states.get("sensor.flipr_myfliprid_water_temp") assert state assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.state == "10.5" diff --git a/tests/components/foobot/test_sensor.py b/tests/components/foobot/test_sensor.py index 93908715888..3b02df55bf4 100644 --- a/tests/components/foobot/test_sensor.py +++ b/tests/components/foobot/test_sensor.py @@ -14,7 +14,7 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_BILLION, CONCENTRATION_PARTS_PER_MILLION, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.exceptions import PlatformNotReady from homeassistant.setup import async_setup_component @@ -43,7 +43,7 @@ async def test_default_setup(hass, aioclient_mock): metrics = { "co2": ["1232.0", CONCENTRATION_PARTS_PER_MILLION], - "temperature": ["21.1", TEMP_CELSIUS], + "temperature": ["21.1", UnitOfTemperature.CELSIUS], "humidity": ["49.5", PERCENTAGE], "pm2_5": ["144.8", CONCENTRATION_MICROGRAMS_PER_CUBIC_METER], "voc": ["340.7", CONCENTRATION_PARTS_PER_BILLION], diff --git a/tests/components/forecast_solar/test_sensor.py b/tests/components/forecast_solar/test_sensor.py index 893730c722e..3735b992a04 100644 --- a/tests/components/forecast_solar/test_sensor.py +++ b/tests/components/forecast_solar/test_sensor.py @@ -15,8 +15,8 @@ from homeassistant.const import ( ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, - ENERGY_KILO_WATT_HOUR, - POWER_WATT, + UnitOfEnergy, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er @@ -44,7 +44,7 @@ async def test_sensors( == "Solar production forecast Estimated energy production - today" ) assert state.attributes.get(ATTR_STATE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY assert ATTR_ICON not in state.attributes @@ -59,7 +59,7 @@ async def test_sensors( == "Solar production forecast Estimated energy production - tomorrow" ) assert state.attributes.get(ATTR_STATE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY assert ATTR_ICON not in state.attributes @@ -104,7 +104,7 @@ async def test_sensors( == "Solar production forecast Estimated power production - now" ) assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER assert ATTR_ICON not in state.attributes @@ -119,7 +119,7 @@ async def test_sensors( == "Solar production forecast Estimated energy production - this hour" ) assert state.attributes.get(ATTR_STATE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY assert ATTR_ICON not in state.attributes @@ -134,7 +134,7 @@ async def test_sensors( == "Solar production forecast Estimated energy production - next hour" ) assert state.attributes.get(ATTR_STATE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY assert ATTR_ICON not in state.attributes @@ -228,6 +228,6 @@ async def test_enabling_disable_by_default( state.attributes.get(ATTR_FRIENDLY_NAME) == f"Solar production forecast {name}" ) assert state.attributes.get(ATTR_STATE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER assert ATTR_ICON not in state.attributes diff --git a/tests/components/fritzbox/test_climate.py b/tests/components/fritzbox/test_climate.py index faed4389310..0a1feb377e0 100644 --- a/tests/components/fritzbox/test_climate.py +++ b/tests/components/fritzbox/test_climate.py @@ -36,7 +36,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, CONF_DEVICES, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.util.dt as dt_util @@ -87,14 +87,14 @@ async def test_setup(hass: HomeAssistant, fritz: Mock): assert ( state.attributes[ATTR_FRIENDLY_NAME] == f"{CONF_FAKE_NAME} Comfort Temperature" ) - assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert ATTR_STATE_CLASS not in state.attributes state = hass.states.get(f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_eco_temperature") assert state assert state.state == "16.0" assert state.attributes[ATTR_FRIENDLY_NAME] == f"{CONF_FAKE_NAME} Eco Temperature" - assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert ATTR_STATE_CLASS not in state.attributes state = hass.states.get( @@ -106,7 +106,7 @@ async def test_setup(hass: HomeAssistant, fritz: Mock): state.attributes[ATTR_FRIENDLY_NAME] == f"{CONF_FAKE_NAME} Next Scheduled Temperature" ) - assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert ATTR_STATE_CLASS not in state.attributes state = hass.states.get( diff --git a/tests/components/fritzbox/test_init.py b/tests/components/fritzbox/test_init.py index dbec8b4ec14..41725a6a6e2 100644 --- a/tests/components/fritzbox/test_init.py +++ b/tests/components/fritzbox/test_init.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, STATE_UNAVAILABLE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -53,7 +53,7 @@ async def test_setup(hass: HomeAssistant, fritz: Mock): "domain": SENSOR_DOMAIN, "platform": FB_DOMAIN, "unique_id": CONF_FAKE_AIN, - "unit_of_measurement": TEMP_CELSIUS, + "unit_of_measurement": UnitOfTemperature.CELSIUS, }, CONF_FAKE_AIN, f"{CONF_FAKE_AIN}_temperature", @@ -106,7 +106,7 @@ async def test_update_unique_id( "domain": SENSOR_DOMAIN, "platform": FB_DOMAIN, "unique_id": f"{CONF_FAKE_AIN}_temperature", - "unit_of_measurement": TEMP_CELSIUS, + "unit_of_measurement": UnitOfTemperature.CELSIUS, }, f"{CONF_FAKE_AIN}_temperature", ), diff --git a/tests/components/fritzbox/test_sensor.py b/tests/components/fritzbox/test_sensor.py index dfb480459da..0077f878b72 100644 --- a/tests/components/fritzbox/test_sensor.py +++ b/tests/components/fritzbox/test_sensor.py @@ -11,7 +11,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, CONF_DEVICES, PERCENTAGE, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.util.dt as dt_util @@ -36,7 +36,7 @@ async def test_setup(hass: HomeAssistant, fritz: Mock): assert state assert state.state == "1.23" assert state.attributes[ATTR_FRIENDLY_NAME] == f"{CONF_FAKE_NAME} Temperature" - assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS + assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT state = hass.states.get(f"{ENTITY_ID}_humidity") diff --git a/tests/components/fritzbox/test_switch.py b/tests/components/fritzbox/test_switch.py index 852b41512f5..01b80872b66 100644 --- a/tests/components/fritzbox/test_switch.py +++ b/tests/components/fritzbox/test_switch.py @@ -16,15 +16,15 @@ from homeassistant.const import ( ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT, CONF_DEVICES, - ELECTRIC_CURRENT_AMPERE, - ELECTRIC_POTENTIAL_VOLT, - ENERGY_KILO_WATT_HOUR, - POWER_WATT, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_UNAVAILABLE, - TEMP_CELSIUS, + UnitOfElectricCurrent, + UnitOfElectricPotential, + UnitOfEnergy, + UnitOfPower, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.util.dt as dt_util @@ -58,35 +58,35 @@ async def test_setup(hass: HomeAssistant, fritz: Mock): f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_temperature", "1.23", f"{CONF_FAKE_NAME} Temperature", - TEMP_CELSIUS, + UnitOfTemperature.CELSIUS, SensorStateClass.MEASUREMENT, ], [ f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_power_consumption", "5.678", f"{CONF_FAKE_NAME} Power Consumption", - POWER_WATT, + UnitOfPower.WATT, SensorStateClass.MEASUREMENT, ], [ f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_total_energy", "1.234", f"{CONF_FAKE_NAME} Total Energy", - ENERGY_KILO_WATT_HOUR, + UnitOfEnergy.KILO_WATT_HOUR, SensorStateClass.TOTAL_INCREASING, ], [ f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_voltage", "230.0", f"{CONF_FAKE_NAME} Voltage", - ELECTRIC_POTENTIAL_VOLT, + UnitOfElectricPotential.VOLT, SensorStateClass.MEASUREMENT, ], [ f"{SENSOR_DOMAIN}.{CONF_FAKE_NAME}_electric_current", "0.025", f"{CONF_FAKE_NAME} Electric Current", - ELECTRIC_CURRENT_AMPERE, + UnitOfElectricCurrent.AMPERE, SensorStateClass.MEASUREMENT, ], ) diff --git a/tests/components/gdacs/test_geo_location.py b/tests/components/gdacs/test_geo_location.py index 83b9efde1e8..b7678e557b5 100644 --- a/tests/components/gdacs/test_geo_location.py +++ b/tests/components/gdacs/test_geo_location.py @@ -29,7 +29,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, CONF_RADIUS, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -131,7 +131,7 @@ async def test_setup(hass): ATTR_EVENT_TYPE: "Drought", ATTR_SEVERITY: "Severity 1", ATTR_VULNERABILITY: "Vulnerability 1", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "gdacs", ATTR_ICON: "mdi:water-off", } @@ -147,7 +147,7 @@ async def test_setup(hass): ATTR_FRIENDLY_NAME: "Tropical Cyclone: Name 2", ATTR_DESCRIPTION: "Description 2", ATTR_EVENT_TYPE: "Tropical Cyclone", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "gdacs", ATTR_ICON: "mdi:weather-hurricane", } @@ -164,7 +164,7 @@ async def test_setup(hass): ATTR_DESCRIPTION: "Description 3", ATTR_EVENT_TYPE: "Tropical Cyclone", ATTR_COUNTRY: "Country 2", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "gdacs", ATTR_ICON: "mdi:weather-hurricane", } diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index 52714ab15a2..4c1ed8ad8c2 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -30,7 +30,7 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, + UnitOfTemperature, ) import homeassistant.core as ha from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback @@ -572,7 +572,7 @@ def _setup_switch(hass, is_on): @pytest.fixture async def setup_comp_3(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, @@ -717,7 +717,7 @@ async def test_no_state_change_when_operation_mode_off_2(hass, setup_comp_3): @pytest.fixture async def setup_comp_4(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, @@ -823,7 +823,7 @@ async def test_mode_change_ac_trigger_on_not_long_enough(hass, setup_comp_4): @pytest.fixture async def setup_comp_5(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, @@ -929,7 +929,7 @@ async def test_mode_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5): @pytest.fixture async def setup_comp_6(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, @@ -1034,7 +1034,7 @@ async def test_mode_change_heater_trigger_on_not_long_enough(hass, setup_comp_6) @pytest.fixture async def setup_comp_7(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, @@ -1107,7 +1107,7 @@ async def test_temp_change_ac_trigger_off_long_enough_3(hass, setup_comp_7): @pytest.fixture async def setup_comp_8(hass): """Initialize components.""" - hass.config.temperature_unit = TEMP_CELSIUS + hass.config.temperature_unit = UnitOfTemperature.CELSIUS assert await async_setup_component( hass, DOMAIN, diff --git a/tests/components/geo_json_events/test_geo_location.py b/tests/components/geo_json_events/test_geo_location.py index 66f5f06ffe9..193c9bfa090 100644 --- a/tests/components/geo_json_events/test_geo_location.py +++ b/tests/components/geo_json_events/test_geo_location.py @@ -20,7 +20,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_URL, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.helpers.dispatcher import DATA_DISPATCHER from homeassistant.setup import async_setup_component @@ -94,7 +94,7 @@ async def test_setup(hass): ATTR_LATITUDE: -31.0, ATTR_LONGITUDE: 150.0, ATTR_FRIENDLY_NAME: "Title 1", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geo_json_events", } assert round(abs(float(state.state) - 15.5), 7) == 0 @@ -107,7 +107,7 @@ async def test_setup(hass): ATTR_LATITUDE: -31.1, ATTR_LONGITUDE: 150.1, ATTR_FRIENDLY_NAME: "Title 2", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geo_json_events", } assert round(abs(float(state.state) - 20.5), 7) == 0 @@ -120,7 +120,7 @@ async def test_setup(hass): ATTR_LATITUDE: -31.2, ATTR_LONGITUDE: 150.2, ATTR_FRIENDLY_NAME: "Title 3", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geo_json_events", } assert round(abs(float(state.state) - 25.5), 7) == 0 diff --git a/tests/components/geonetnz_quakes/test_geo_location.py b/tests/components/geonetnz_quakes/test_geo_location.py index 327829d3d4b..2f58a7fd095 100644 --- a/tests/components/geonetnz_quakes/test_geo_location.py +++ b/tests/components/geonetnz_quakes/test_geo_location.py @@ -23,7 +23,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, CONF_RADIUS, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -99,7 +99,7 @@ async def test_setup(hass): ATTR_DEPTH: 10.5, ATTR_MMI: 5, ATTR_QUALITY: "best", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geonetnz_quakes", ATTR_ICON: "mdi:pulse", } @@ -114,7 +114,7 @@ async def test_setup(hass): ATTR_LONGITUDE: -3.1, ATTR_FRIENDLY_NAME: "Title 2", ATTR_MAGNITUDE: 4.6, - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geonetnz_quakes", ATTR_ICON: "mdi:pulse", } @@ -129,7 +129,7 @@ async def test_setup(hass): ATTR_LONGITUDE: -3.2, ATTR_FRIENDLY_NAME: "Title 3", ATTR_LOCALITY: "Locality 3", - ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, + ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS, ATTR_SOURCE: "geonetnz_quakes", ATTR_ICON: "mdi:pulse", } diff --git a/tests/components/goalzero/test_sensor.py b/tests/components/goalzero/test_sensor.py index 402c03f2e51..58869bead65 100644 --- a/tests/components/goalzero/test_sensor.py +++ b/tests/components/goalzero/test_sensor.py @@ -10,15 +10,14 @@ from homeassistant.components.sensor import ( from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_UNIT_OF_MEASUREMENT, - ELECTRIC_CURRENT_AMPERE, - ELECTRIC_POTENTIAL_VOLT, - ENERGY_WATT_HOUR, PERCENTAGE, - POWER_WATT, SIGNAL_STRENGTH_DECIBELS, - TEMP_CELSIUS, - TIME_MINUTES, - TIME_SECONDS, + UnitOfElectricCurrent, + UnitOfElectricPotential, + UnitOfEnergy, + UnitOfPower, + UnitOfTemperature, + UnitOfTime, ) from homeassistant.core import HomeAssistant @@ -38,37 +37,43 @@ async def test_sensors( state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_in") assert state.state == "0.0" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT state = hass.states.get(f"sensor.{DEFAULT_NAME}_amps_in") assert state.state == "0.0" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ELECTRIC_CURRENT_AMPERE + assert ( + state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE + ) assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_out") assert state.state == "50.5" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT state = hass.states.get(f"sensor.{DEFAULT_NAME}_amps_out") assert state.state == "2.1" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ELECTRIC_CURRENT_AMPERE + assert ( + state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE + ) assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT state = hass.states.get(f"sensor.{DEFAULT_NAME}_wh_out") assert state.state == "5.23" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING state = hass.states.get(f"sensor.{DEFAULT_NAME}_wh_stored") assert state.state == "1330" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_WATT_HOUR + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT state = hass.states.get(f"sensor.{DEFAULT_NAME}_volts") assert state.state == "12.0" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ELECTRIC_POTENTIAL_VOLT + assert ( + state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricPotential.VOLT + ) assert state.attributes.get(ATTR_STATE_CLASS) is None state = hass.states.get(f"sensor.{DEFAULT_NAME}_state_of_charge_percent") assert state.state == "95" @@ -78,12 +83,12 @@ async def test_sensors( state = hass.states.get(f"sensor.{DEFAULT_NAME}_time_to_empty_full") assert state.state == "-1" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DURATION - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TIME_MINUTES + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTime.MINUTES assert state.attributes.get(ATTR_STATE_CLASS) is None state = hass.states.get(f"sensor.{DEFAULT_NAME}_temperature") assert state.state == "25" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_STATE_CLASS) is None state = hass.states.get(f"sensor.{DEFAULT_NAME}_wi_fi_strength") assert state.state == "-62" @@ -93,7 +98,7 @@ async def test_sensors( state = hass.states.get(f"sensor.{DEFAULT_NAME}_total_run_time") assert state.state == "1720984" assert state.attributes.get(ATTR_DEVICE_CLASS) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TIME_SECONDS + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTime.SECONDS assert state.attributes.get(ATTR_STATE_CLASS) is None state = hass.states.get(f"sensor.{DEFAULT_NAME}_wi_fi_ssid") assert state.state == "wifi" diff --git a/tests/components/google_assistant/test_google_assistant.py b/tests/components/google_assistant/test_google_assistant.py index 97484f31341..441599885f9 100644 --- a/tests/components/google_assistant/test_google_assistant.py +++ b/tests/components/google_assistant/test_google_assistant.py @@ -20,7 +20,7 @@ from homeassistant.components import ( media_player, switch, ) -from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES +from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES, UnitOfTemperature from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity import EntityCategory @@ -293,7 +293,7 @@ async def test_query_climate_request(hass_fixture, assistant_client, auth_header async def test_query_climate_request_f(hass_fixture, assistant_client, auth_header): """Test a query request.""" # Mock demo devices as fahrenheit to see if we convert to celsius - hass_fixture.config.units.temperature_unit = const.TEMP_FAHRENHEIT + hass_fixture.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT for entity_id in ("climate.hvac", "climate.heatpump", "climate.ecobee"): state = hass_fixture.states.get(entity_id) attr = dict(state.attributes) @@ -347,7 +347,7 @@ async def test_query_climate_request_f(hass_fixture, assistant_client, auth_head "thermostatHumidityAmbient": 54, "currentFanSpeedSetting": "On High", } - hass_fixture.config.units.temperature_unit = const.TEMP_CELSIUS + hass_fixture.config.units.temperature_unit = UnitOfTemperature.CELSIUS async def test_query_humidifier_request(hass_fixture, assistant_client, auth_header): diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index 26b85f19c58..29c2927b157 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -21,7 +21,7 @@ from homeassistant.components.google_assistant import ( trait, ) from homeassistant.config import async_process_ha_core_config -from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, __version__ +from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, __version__ from homeassistant.core import EVENT_CALL_SERVICE, State from homeassistant.helpers import device_registry, entity_platform from homeassistant.setup import async_setup_component @@ -827,7 +827,11 @@ async def test_raising_error_trait(hass): hass.states.async_set( "climate.bla", HVACMode.HEAT, - {ATTR_MIN_TEMP: 15, ATTR_MAX_TEMP: 30, ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}, + { + ATTR_MIN_TEMP: 15, + ATTR_MAX_TEMP: 30, + ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + }, ) events = async_capture_events(hass, EVENT_COMMAND_RECEIVED) diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index 9d80c7ff507..a6db99e1e38 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -52,8 +52,7 @@ from homeassistant.const import ( STATE_STANDBY, STATE_UNAVAILABLE, STATE_UNKNOWN, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) from homeassistant.core import DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE, State from homeassistant.util import color @@ -833,7 +832,7 @@ async def test_temperature_setting_climate_onoff(hass): assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) - hass.config.units.temperature_unit = TEMP_FAHRENHEIT + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT trt = trait.TemperatureSettingTrait( hass, @@ -878,7 +877,7 @@ async def test_temperature_setting_climate_no_modes(hass): assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS trt = trait.TemperatureSettingTrait( hass, @@ -904,7 +903,7 @@ async def test_temperature_setting_climate_range(hass): assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) - hass.config.units.temperature_unit = TEMP_FAHRENHEIT + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT trt = trait.TemperatureSettingTrait( hass, @@ -978,7 +977,7 @@ async def test_temperature_setting_climate_range(hass): {}, ) assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS async def test_temperature_setting_climate_setpoint(hass): @@ -986,7 +985,7 @@ async def test_temperature_setting_climate_setpoint(hass): assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS trt = trait.TemperatureSettingTrait( hass, @@ -1041,7 +1040,7 @@ async def test_temperature_setting_climate_setpoint_auto(hass): Setpoint in auto mode. """ - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS trt = trait.TemperatureSettingTrait( hass, @@ -1088,7 +1087,7 @@ async def test_temperature_setting_climate_setpoint_auto(hass): async def test_temperature_control(hass): """Test TemperatureControl trait support for sensor domain.""" - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS trt = trait.TemperatureControlTrait( hass, @@ -2891,10 +2890,10 @@ async def test_temperature_control_sensor(hass): @pytest.mark.parametrize( "unit_in,unit_out,state,ambient", [ - (TEMP_FAHRENHEIT, "F", "70", 21.1), - (TEMP_CELSIUS, "C", "21.1", 21.1), - (TEMP_FAHRENHEIT, "F", "unavailable", None), - (TEMP_FAHRENHEIT, "F", "unknown", None), + (UnitOfTemperature.FAHRENHEIT, "F", "70", 21.1), + (UnitOfTemperature.CELSIUS, "C", "21.1", 21.1), + (UnitOfTemperature.FAHRENHEIT, "F", "unavailable", None), + (UnitOfTemperature.FAHRENHEIT, "F", "unknown", None), ], ) async def test_temperature_control_sensor_data(hass, unit_in, unit_out, state, ambient): @@ -2924,7 +2923,7 @@ async def test_temperature_control_sensor_data(hass, unit_in, unit_out, state, a } else: assert trt.query_attributes() == {} - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS async def test_humidity_setting_sensor(hass): diff --git a/tests/components/gree/test_climate.py b/tests/components/gree/test_climate.py index de873726c44..d3cf418600c 100644 --- a/tests/components/gree/test_climate.py +++ b/tests/components/gree/test_climate.py @@ -44,8 +44,7 @@ from homeassistant.const import ( SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_UNAVAILABLE, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature, ) import homeassistant.util.dt as dt_util @@ -360,14 +359,15 @@ async def test_send_power_off_device_timeout(hass, discovery, device, mock_now): @pytest.mark.parametrize( - "units,temperature", [(TEMP_CELSIUS, 26), (TEMP_FAHRENHEIT, 74)] + "units,temperature", + [(UnitOfTemperature.CELSIUS, 26), (UnitOfTemperature.FAHRENHEIT, 74)], ) async def test_send_target_temperature(hass, discovery, device, units, temperature): """Test for sending target temperature command to the device.""" hass.config.units.temperature_unit = units fake_device = device() - if units == TEMP_FAHRENHEIT: + if units == UnitOfTemperature.FAHRENHEIT: fake_device.temperature_units = 1 await async_setup_gree(hass) @@ -392,18 +392,19 @@ async def test_send_target_temperature(hass, discovery, device, units, temperatu # Reset config temperature_unit back to CELSIUS, required for # additional tests outside this component. - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS @pytest.mark.parametrize( - "units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)] + "units,temperature", + [(UnitOfTemperature.CELSIUS, 25), (UnitOfTemperature.FAHRENHEIT, 74)], ) async def test_send_target_temperature_device_timeout( hass, discovery, device, units, temperature ): """Test for sending target temperature command to the device with a device timeout.""" hass.config.units.temperature_unit = units - if units == TEMP_FAHRENHEIT: + if units == UnitOfTemperature.FAHRENHEIT: device().temperature_units = 1 device().push_state_update.side_effect = DeviceTimeoutError @@ -421,16 +422,17 @@ async def test_send_target_temperature_device_timeout( assert state.attributes.get(ATTR_TEMPERATURE) == temperature # Reset config temperature_unit back to CELSIUS, required for additional tests outside this component. - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS @pytest.mark.parametrize( - "units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)] + "units,temperature", + [(UnitOfTemperature.CELSIUS, 25), (UnitOfTemperature.FAHRENHEIT, 74)], ) async def test_update_target_temperature(hass, discovery, device, units, temperature): """Test for updating target temperature from the device.""" hass.config.units.temperature_unit = units - if units == TEMP_FAHRENHEIT: + if units == UnitOfTemperature.FAHRENHEIT: device().temperature_units = 1 device().target_temperature = temperature @@ -441,7 +443,7 @@ async def test_update_target_temperature(hass, discovery, device, units, tempera assert state.attributes.get(ATTR_TEMPERATURE) == temperature # Reset config temperature_unit back to CELSIUS, required for additional tests outside this component. - hass.config.units.temperature_unit = TEMP_CELSIUS + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS @pytest.mark.parametrize( diff --git a/tests/components/greeneye_monitor/conftest.py b/tests/components/greeneye_monitor/conftest.py index 00b534bb06d..eabac97d1cc 100644 --- a/tests/components/greeneye_monitor/conftest.py +++ b/tests/components/greeneye_monitor/conftest.py @@ -6,7 +6,7 @@ import pytest from homeassistant.components.greeneye_monitor import DOMAIN from homeassistant.components.sensor import SensorDeviceClass -from homeassistant.const import ELECTRIC_POTENTIAL_VOLT, POWER_WATT +from homeassistant.const import UnitOfElectricPotential, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_registry import ( RegistryEntry, @@ -61,7 +61,7 @@ def assert_power_sensor_registered( ) -> None: """Assert that a power sensor entity was registered properly.""" sensor = assert_sensor_registered(hass, serial_number, "current", number, name) - assert sensor.unit_of_measurement == POWER_WATT + assert sensor.unit_of_measurement == UnitOfPower.WATT assert sensor.original_device_class is SensorDeviceClass.POWER @@ -70,7 +70,7 @@ def assert_voltage_sensor_registered( ) -> None: """Assert that a voltage sensor entity was registered properly.""" sensor = assert_sensor_registered(hass, serial_number, "volts", number, name) - assert sensor.unit_of_measurement == ELECTRIC_POTENTIAL_VOLT + assert sensor.unit_of_measurement == UnitOfElectricPotential.VOLT assert sensor.original_device_class is SensorDeviceClass.VOLTAGE