Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
Robert Resch
8158da573a update translations 2023-12-12 13:04:17 +00:00
Robert Resch
983f97fdb3 sort 2023-12-12 12:57:52 +00:00
Robert Resch
1ee4f0fb58 list all units of measurement 2023-12-12 12:48:07 +00:00
Robert Resch
190d8aef0a Add all units of measurement for selector in scrape 2023-12-11 09:25:54 +00:00
3 changed files with 55 additions and 9 deletions

View file

@ -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,
)
),
}

View file

@ -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"
}
}
}
}

View file

@ -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"