|
31 | 31 | PassiveBluetoothEntityKey, |
32 | 32 | PassiveBluetoothProcessorCoordinator, |
33 | 33 | PassiveBluetoothProcessorEntity, |
| 34 | + deserialize_entity_description, |
34 | 35 | ) |
35 | 36 | from homeassistant.components.sensor import ( |
36 | 37 | DOMAIN as SENSOR_DOMAIN, |
37 | 38 | SensorDeviceClass, |
38 | 39 | SensorEntityDescription, |
| 40 | + SensorStateClass, |
39 | 41 | ) |
40 | 42 | from homeassistant.config_entries import current_entry |
41 | 43 | from homeassistant.const import UnitOfTemperature |
42 | 44 | from homeassistant.core import CoreState, HomeAssistant, callback |
43 | 45 | from homeassistant.helpers.device_registry import DeviceInfo |
| 46 | +from homeassistant.helpers.entity import EntityDescription |
44 | 47 | from homeassistant.helpers.typing import UNDEFINED |
45 | 48 | from homeassistant.setup import async_setup_component |
46 | 49 | from homeassistant.util import dt as dt_util |
@@ -1920,3 +1923,55 @@ def _mock_update_method( |
1920 | 1923 | assert sensor_entity.translation_key is None |
1921 | 1924 |
|
1922 | 1925 | cancel_coordinator() |
| 1926 | + |
| 1927 | + |
| 1928 | +@pytest.mark.parametrize( |
| 1929 | + ("description_type", "description_dict", "expected_description"), |
| 1930 | + [ |
| 1931 | + ( |
| 1932 | + SensorEntityDescription, |
| 1933 | + { |
| 1934 | + "key": "humidity", |
| 1935 | + "native_unit_of_measurement": "%", |
| 1936 | + "device_class": "humidity", |
| 1937 | + "state_class": "measurement", |
| 1938 | + }, |
| 1939 | + SensorEntityDescription( |
| 1940 | + key="humidity", |
| 1941 | + native_unit_of_measurement="%", |
| 1942 | + device_class=SensorDeviceClass.HUMIDITY, |
| 1943 | + state_class=SensorStateClass.MEASUREMENT, |
| 1944 | + ), |
| 1945 | + ), |
| 1946 | + ( |
| 1947 | + BinarySensorEntityDescription, |
| 1948 | + { |
| 1949 | + "key": "motion", |
| 1950 | + "device_class": "motion", |
| 1951 | + }, |
| 1952 | + BinarySensorEntityDescription( |
| 1953 | + key="motion", |
| 1954 | + device_class=BinarySensorDeviceClass.MOTION, |
| 1955 | + ), |
| 1956 | + ), |
| 1957 | + ( |
| 1958 | + SensorEntityDescription, |
| 1959 | + { |
| 1960 | + "key": "temperature", |
| 1961 | + "name": None, |
| 1962 | + }, |
| 1963 | + SensorEntityDescription( |
| 1964 | + key="temperature", |
| 1965 | + name=None, |
| 1966 | + ), |
| 1967 | + ), |
| 1968 | + ], |
| 1969 | +) |
| 1970 | +def test_deserialize_entity_description( |
| 1971 | + description_type: type[EntityDescription], |
| 1972 | + description_dict: dict[str, Any], |
| 1973 | + expected_description: EntityDescription, |
| 1974 | +) -> None: |
| 1975 | + """Test deserializing an entity description.""" |
| 1976 | + description = deserialize_entity_description(description_type, description_dict) |
| 1977 | + assert description == expected_description |
0 commit comments