1 """Platform for sensor integration."""
3 from switchbot_api
import Device, SwitchBotAPI
8 SensorEntityDescription,
13 CONCENTRATION_PARTS_PER_MILLION,
20 from .
import SwitchbotCloudData
21 from .const
import DOMAIN
22 from .coordinator
import SwitchBotCoordinator
23 from .entity
import SwitchBotCloudEntity
25 SENSOR_TYPE_TEMPERATURE =
"temperature"
26 SENSOR_TYPE_HUMIDITY =
"humidity"
27 SENSOR_TYPE_BATTERY =
"battery"
28 SENSOR_TYPE_CO2 =
"CO2"
30 METER_PLUS_SENSOR_DESCRIPTIONS = (
32 key=SENSOR_TYPE_TEMPERATURE,
33 device_class=SensorDeviceClass.TEMPERATURE,
34 state_class=SensorStateClass.MEASUREMENT,
35 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
38 key=SENSOR_TYPE_HUMIDITY,
39 device_class=SensorDeviceClass.HUMIDITY,
40 state_class=SensorStateClass.MEASUREMENT,
41 native_unit_of_measurement=PERCENTAGE,
44 key=SENSOR_TYPE_BATTERY,
45 device_class=SensorDeviceClass.BATTERY,
46 state_class=SensorStateClass.MEASUREMENT,
47 native_unit_of_measurement=PERCENTAGE,
51 METER_PRO_CO2_SENSOR_DESCRIPTIONS = (
52 *METER_PLUS_SENSOR_DESCRIPTIONS,
55 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
56 state_class=SensorStateClass.MEASUREMENT,
57 device_class=SensorDeviceClass.CO2,
65 async_add_entities: AddEntitiesCallback,
67 """Set up SwitchBot Cloud entry."""
68 data: SwitchbotCloudData = hass.data[DOMAIN][config.entry_id]
72 for device, coordinator
in data.devices.sensors
74 METER_PRO_CO2_SENSOR_DESCRIPTIONS
75 if device.device_type ==
"MeterPro(CO2)"
76 else METER_PLUS_SENSOR_DESCRIPTIONS
82 """Representation of a SwitchBot Cloud sensor entity."""
88 coordinator: SwitchBotCoordinator,
89 description: SensorEntityDescription,
91 """Initialize SwitchBot Cloud sensor entity."""
92 super().
__init__(api, device, coordinator)
98 """Handle updated data from the coordinator."""
99 if not self.coordinator.data:
None __init__(self, SwitchBotAPI api, Device device, SwitchBotCoordinator coordinator, SensorEntityDescription description)
None _handle_coordinator_update(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config, AddEntitiesCallback async_add_entities)