Use SoundPressure unit and device class in integrations (#83585)

* Use SoundPressure unit and device class in integrations

* Adjust tests
pull/83611/head
epenet 2022-12-09 07:56:09 +01:00 committed by GitHub
parent 558dceac42
commit 061cef1a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -31,9 +31,9 @@ from homeassistant.const import (
POWER_WATT, POWER_WATT,
PRESSURE_HPA, PRESSURE_HPA,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
SOUND_PRESSURE_DB,
TEMP_CELSIUS, TEMP_CELSIUS,
Platform, Platform,
UnitOfSoundPressure,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -330,7 +330,8 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
key=CharacteristicsTypes.VENDOR_NETATMO_NOISE, key=CharacteristicsTypes.VENDOR_NETATMO_NOISE,
name="Noise", name="Noise",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=SOUND_PRESSURE_DB, native_unit_of_measurement=UnitOfSoundPressure.DECIBEL,
device_class=SensorDeviceClass.SOUND_PRESSURE,
), ),
} }

View File

@ -25,12 +25,12 @@ from homeassistant.const import (
MASS_KILOGRAMS, MASS_KILOGRAMS,
PERCENTAGE, PERCENTAGE,
POWER_WATT, POWER_WATT,
SOUND_PRESSURE_DB,
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
VOLUME_CUBIC_METERS, VOLUME_CUBIC_METERS,
Platform, Platform,
UnitOfApparentPower, UnitOfApparentPower,
UnitOfSoundPressure,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -134,8 +134,8 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_LEVEL_S_SOUND": SensorEntityDescription( "V_LEVEL_S_SOUND": SensorEntityDescription(
key="V_LEVEL_S_SOUND", key="V_LEVEL_S_SOUND",
native_unit_of_measurement=SOUND_PRESSURE_DB, native_unit_of_measurement=UnitOfSoundPressure.DECIBEL,
icon="mdi:volume-high", device_class=SensorDeviceClass.SOUND_PRESSURE,
), ),
"V_LEVEL_S_VIBRATION": SensorEntityDescription( "V_LEVEL_S_VIBRATION": SensorEntityDescription(
key="V_LEVEL_S_VIBRATION", key="V_LEVEL_S_VIBRATION",

View File

@ -20,10 +20,10 @@ from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
DEGREE, DEGREE,
PERCENTAGE, PERCENTAGE,
SOUND_PRESSURE_DB,
UnitOfPower, UnitOfPower,
UnitOfPrecipitationDepth, UnitOfPrecipitationDepth,
UnitOfPressure, UnitOfPressure,
UnitOfSoundPressure,
UnitOfSpeed, UnitOfSpeed,
UnitOfTemperature, UnitOfTemperature,
) )
@ -129,8 +129,8 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Noise", name="Noise",
netatmo_name="noise", netatmo_name="noise",
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
native_unit_of_measurement=SOUND_PRESSURE_DB, native_unit_of_measurement=UnitOfSoundPressure.DECIBEL,
icon="mdi:volume-high", device_class=SensorDeviceClass.SOUND_PRESSURE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
NetatmoSensorEntityDescription( NetatmoSensorEntityDescription(

View File

@ -105,7 +105,7 @@ async def test_sound_sensor(
assert state assert state
assert state.state == "10" assert state.state == "10"
assert state.attributes[ATTR_ICON] == "mdi:volume-high" assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.SOUND_PRESSURE
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "dB" assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "dB"