1 """Sensor platform for motionEye."""
3 from __future__
import annotations
6 from types
import MappingProxyType
9 from motioneye_client.client
import MotionEyeClient
10 from motioneye_client.const
import KEY_ACTIONS
19 from .
import get_camera_from_cameras, listen_for_new_cameras
20 from .const
import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_ACTION_SENSOR
21 from .entity
import MotionEyeEntity
23 _LOGGER = logging.getLogger(__name__)
27 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
29 """Set up motionEye from a config entry."""
30 entry_data = hass.data[DOMAIN][entry.entry_id]
33 def camera_add(camera: dict[str, Any]) ->
None:
34 """Add a new motionEye camera."""
40 entry_data[CONF_CLIENT],
41 entry_data[CONF_COORDINATOR],
51 """motionEye action sensor camera."""
53 _attr_translation_key =
"actions"
58 camera: dict[str, Any],
59 client: MotionEyeClient,
60 coordinator: DataUpdateCoordinator,
61 options: MappingProxyType[str, str],
63 """Initialize an action sensor."""
66 TYPE_MOTIONEYE_ACTION_SENSOR,
72 key=TYPE_MOTIONEYE_ACTION_SENSOR, entity_registry_enabled_default=
False
78 """Return the value reported by the sensor."""
79 return len(self.
_camera_camera.
get(KEY_ACTIONS, []))
if self.
_camera_camera
else 0
83 """Add actions as attribute."""
84 if actions := (self.
_camera_camera.
get(KEY_ACTIONS)
if self.
_camera_camera
else None):
85 return {KEY_ACTIONS: actions}
90 """Handle updated data from the coordinator."""
None __init__(self, str config_entry_id, dict[str, Any] camera, MotionEyeClient client, DataUpdateCoordinator coordinator, MappingProxyType[str, str] options)
StateType native_value(self)
None _handle_coordinator_update(self)
dict[str, Any]|None extra_state_attributes(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
None listen_for_new_cameras(HomeAssistant hass, ConfigEntry entry, Callable add_func)
dict[str, Any]|None get_camera_from_cameras(int camera_id, dict[str, Any]|None data)