1 """Support for SwitchBot sensors."""
3 from __future__
import annotations
9 SensorEntityDescription,
13 CONCENTRATION_PARTS_PER_MILLION,
15 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
23 from .coordinator
import SwitchbotConfigEntry, SwitchbotDataUpdateCoordinator
24 from .entity
import SwitchbotEntity
28 SENSOR_TYPES: dict[str, SensorEntityDescription] = {
31 translation_key=
"bluetooth_signal",
32 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
33 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
34 state_class=SensorStateClass.MEASUREMENT,
35 entity_registry_enabled_default=
False,
36 entity_category=EntityCategory.DIAGNOSTIC,
40 translation_key=
"wifi_signal",
41 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
42 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
43 state_class=SensorStateClass.MEASUREMENT,
44 entity_registry_enabled_default=
False,
45 entity_category=EntityCategory.DIAGNOSTIC,
49 native_unit_of_measurement=PERCENTAGE,
50 device_class=SensorDeviceClass.BATTERY,
51 state_class=SensorStateClass.MEASUREMENT,
52 entity_category=EntityCategory.DIAGNOSTIC,
56 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
57 state_class=SensorStateClass.MEASUREMENT,
58 device_class=SensorDeviceClass.CO2,
62 translation_key=
"light_level",
63 native_unit_of_measurement=
"Level",
64 state_class=SensorStateClass.MEASUREMENT,
68 native_unit_of_measurement=PERCENTAGE,
69 state_class=SensorStateClass.MEASUREMENT,
70 device_class=SensorDeviceClass.HUMIDITY,
75 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
76 state_class=SensorStateClass.MEASUREMENT,
77 device_class=SensorDeviceClass.TEMPERATURE,
81 native_unit_of_measurement=UnitOfPower.WATT,
82 state_class=SensorStateClass.MEASUREMENT,
83 device_class=SensorDeviceClass.POWER,
90 entry: SwitchbotConfigEntry,
91 async_add_entities: AddEntitiesCallback,
93 """Set up Switchbot sensor based on a config entry."""
94 coordinator = entry.runtime_data
97 for sensor
in coordinator.device.parsed_data
98 if sensor
in SENSOR_TYPES
105 """Representation of a Switchbot sensor."""
109 coordinator: SwitchbotDataUpdateCoordinator,
112 """Initialize the Switchbot sensor."""
120 """Return the state of the sensor."""
125 """Representation of a Switchbot RSSI sensor."""
129 """Return the state of the sensor."""
137 return service_info.rssi
dict[str, Any] parsed_data(self)
str|int|None native_value(self)
None __init__(self, SwitchbotDataUpdateCoordinator coordinator, str sensor)
BluetoothServiceInfoBleak|None async_last_service_info(HomeAssistant hass, str address, bool connectable=True)
None async_setup_entry(HomeAssistant hass, SwitchbotConfigEntry entry, AddEntitiesCallback async_add_entities)