1 """Support for Soma sensors."""
3 from datetime
import timedelta
12 from .const
import API, DEVICES, DOMAIN
13 from .entity
import SomaEntity
20 config_entry: ConfigEntry,
21 async_add_entities: AddEntitiesCallback,
23 """Set up the Soma sensor platform."""
25 devices = hass.data[DOMAIN][DEVICES]
28 [
SomaSensor(sensor, hass.data[DOMAIN][API])
for sensor
in devices],
True
33 """Representation of a Soma cover device."""
35 _attr_device_class = SensorDeviceClass.BATTERY
36 _attr_native_unit_of_measurement = PERCENTAGE
40 """Return the state of the entity."""
43 @Throttle(MIN_TIME_BETWEEN_UPDATES)
45 """Update the sensor with the latest data."""
47 _battery = response.get(
"battery_percentage")
53 _battery = round(2 * (response[
"battery_level"] - 360))
54 battery =
max(
min(100, _battery), 0)
dict get_battery_level_from_api(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)