1 """Support for Vera sensors."""
3 from __future__
import annotations
5 from datetime
import timedelta
6 from typing
import cast
8 import pyvera
as veraApi
26 from .common
import ControllerData, get_controller_data
27 from .entity
import VeraEntity
35 async_add_entities: AddEntitiesCallback,
37 """Set up the sensor config entry."""
42 for device
in controller_data.devices[Platform.SENSOR]
49 """Representation of a Vera Sensor."""
52 self, vera_device: veraApi.VeraSensor, controller_data: ControllerData
54 """Initialize the sensor."""
55 self._temperature_units: str |
None =
None
57 VeraEntity.__init__(self, vera_device, controller_data)
59 if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
61 elif self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
63 elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
65 elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
67 if self.vera_device.category == veraApi.CATEGORY_LIGHT_SENSOR:
69 elif self.vera_device.category == veraApi.CATEGORY_UV_SENSOR:
71 elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
73 elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
77 """Update the state."""
79 if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:
82 vera_temp_units = self.vera_device.vera_controller.temperature_units
84 if vera_temp_units ==
"F":
89 elif self.vera_device.category
in (
90 veraApi.CATEGORY_LIGHT_SENSOR,
91 veraApi.CATEGORY_UV_SENSOR,
94 elif self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR:
96 elif self.vera_device.category == veraApi.CATEGORY_SCENE_CONTROLLER:
97 controller = cast(veraApi.VeraSceneController, self.vera_device)
98 value = controller.get_last_scene_id(
True)
99 time = controller.get_last_scene_time(
True)
105 elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
107 elif self.vera_device.is_trippable:
108 tripped = self.vera_device.is_tripped
None __init__(self, veraApi.VeraSensor vera_device, ControllerData controller_data)
_attr_native_unit_of_measurement
ControllerData get_controller_data(HomeAssistant hass, ConfigEntry config_entry)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)