diff --git a/homeassistant/components/scrape/config_flow.py b/homeassistant/components/scrape/config_flow.py index b4305b3948e..7af347acbc5 100644 --- a/homeassistant/components/scrape/config_flow.py +++ b/homeassistant/components/scrape/config_flow.py @@ -34,7 +34,7 @@ from homeassistant.const import ( CONF_VERIFY_SSL, HTTP_BASIC_AUTHENTICATION, HTTP_DIGEST_AUTHENTICATION, - UnitOfTemperature, + UNITS_OF_MEASUREMENT, ) from homeassistant.core import async_get_hass from homeassistant.helpers import config_validation as cv, entity_registry as er @@ -124,11 +124,10 @@ SENSOR_SETUP = { ), vol.Optional(CONF_UNIT_OF_MEASUREMENT): SelectSelector( SelectSelectorConfig( - options=[cls.value for cls in UnitOfTemperature], + options=sorted(UNITS_OF_MEASUREMENT), custom_value=True, mode=SelectSelectorMode.DROPDOWN, translation_key="unit_of_measurement", - sort=True, ) ), } diff --git a/homeassistant/components/scrape/strings.json b/homeassistant/components/scrape/strings.json index 217e69b27df..06e0bd50af8 100644 --- a/homeassistant/components/scrape/strings.json +++ b/homeassistant/components/scrape/strings.json @@ -48,7 +48,7 @@ "value_template": "Defines a template to get the state of the sensor", "device_class": "The type/class of the sensor to set the icon in the frontend", "state_class": "The state_class of the sensor", - "unit_of_measurement": "Choose temperature measurement or create your own" + "unit_of_measurement": "Choose a unit of measurement or create your own" } } } @@ -190,11 +190,6 @@ "total": "[%key:component::sensor::entity_component::_::state_attributes::state_class::state::total%]", "total_increasing": "[%key:component::sensor::entity_component::_::state_attributes::state_class::state::total_increasing%]" } - }, - "unit_of_measurement": { - "options": { - "none": "No unit of measurement" - } } } } diff --git a/homeassistant/const.py b/homeassistant/const.py index 8da1c251b4e..1ab0ac352f7 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -1051,6 +1051,58 @@ DATA_RATE_GIBIBYTES_PER_SECOND: Final = "GiB/s" """Deprecated: please use UnitOfDataRate.GIBIBYTES_PER_SECOND""" +UNITS_OF_MEASUREMENT: Final[frozenset[str]] = frozenset( + { + unit + for unit_type in ( + UnitOfApparentPower, + UnitOfPower, + UnitOfEnergy, + UnitOfElectricCurrent, + UnitOfElectricPotential, + UnitOfTemperature, + UnitOfTime, + UnitOfLength, + UnitOfFrequency, + UnitOfPressure, + UnitOfSoundPressure, + UnitOfVolume, + UnitOfVolumeFlowRate, + UnitOfMass, + UnitOfIrradiance, + UnitOfVolumetricFlux, + UnitOfPrecipitationDepth, + UnitOfSpeed, + UnitOfInformation, + UnitOfDataRate, + ) + for unit in unit_type + } +).union( + { + POWER_VOLT_AMPERE_REACTIVE, + DEGREE, + CURRENCY_EURO, + CURRENCY_DOLLAR, + CURRENCY_CENT, + AREA_SQUARE_METERS, + CONDUCTIVITY, + LIGHT_LUX, + UV_INDEX, + PERCENTAGE, + REVOLUTIONS_PER_MINUTE, + CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, + CONCENTRATION_MICROGRAMS_PER_CUBIC_FOOT, + CONCENTRATION_PARTS_PER_CUBIC_METER, + CONCENTRATION_PARTS_PER_MILLION, + CONCENTRATION_PARTS_PER_BILLION, + SIGNAL_STRENGTH_DECIBELS, + SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + } +) + + # States COMPRESSED_STATE_STATE = "s" COMPRESSED_STATE_ATTRIBUTES = "a"