-
Notifications
You must be signed in to change notification settings - Fork 6
/
camera.py
198 lines (163 loc) · 6.94 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import logging
import json
import asyncio
import aiohttp
import async_timeout
import collections
from typing import Dict
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers import config_validation as cv, entity_platform, service
from homeassistant.components.ffmpeg.camera import (
FFmpegCamera,
CONF_INPUT,
CONF_EXTRA_ARGUMENTS,
DEFAULT_ARGUMENTS
)
from homeassistant.components.camera import (
DEFAULT_CONTENT_TYPE,
PLATFORM_SCHEMA,
CameraEntityFeature,
Camera,
)
from homeassistant.const import (
CONF_AUTHENTICATION,
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
CONF_VERIFY_SSL,
HTTP_BASIC_AUTHENTICATION,
HTTP_DIGEST_AUTHENTICATION,
)
from homeassistant.components.generic.camera import (
CONF_CONTENT_TYPE,
CONF_LIMIT_REFETCH_TO_URL_CHANGE,
CONF_STILL_IMAGE_URL,
CONF_STREAM_SOURCE,
CONF_FRAMERATE
)
from .base_class import FreeboxBaseClass
from .const import DOMAIN, VALUE_NOT_SET
from .router import FreeboxRouter
_LOGGER = logging.getLogger(__name__)
'''
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
router = hass.data[DOMAIN][entry.unique_id]
tracked = set()
@callback
def update_router():
add_entities(hass, router, async_add_entities, tracked)
router.listeners.append(async_dispatcher_connect(hass, router.signal_device_new, update_router))
update_router()
platform = entity_platform.current_platform.get()
platform.async_register_entity_service("flip",{},"async_flip",)
@callback
def add_entities(hass, router, async_add_entities, tracked):
"""Add new cover from the router."""
new_tracked = []
#_LOGGER.warning(router.nodes)
for nodeId, node in router.nodes.items():
if (node["category"]!="camera") or (node["id"] in tracked):
continue
new_tracked.append(FreeboxCamera(hass, router, node))
tracked.add(node["id"] )
if new_tracked:
async_add_entities(new_tracked, True)
'''
async def async_setup_entry(hass, entry, async_add_entities):
router = hass.data[DOMAIN][entry.unique_id]
entities = []
for nodeId, node in router.nodes.items():
if node["category"]=="camera":
entities.append(FreeboxCamera(hass, router, node))
async_add_entities(entities, True)
platform = entity_platform.current_platform.get()
platform.async_register_entity_service("flip",{},"async_flip",)
class FreeboxCamera(FreeboxBaseClass, FFmpegCamera):
def __init__(self, hass, router, node):
"""Initialize a camera."""
super().__init__(hass, router, node)
device_info = {CONF_NAME: node["label"].strip(),CONF_INPUT: node["props"]["Stream"],CONF_EXTRA_ARGUMENTS: DEFAULT_ARGUMENTS }
FFmpegCamera.__init__(self, hass, device_info)
self._supported_features = CameraEntityFeature.STREAM
self.update_parameters(node)
self._command_flip = self.get_command_id(node['show_endpoints'], "slot", "flip")
self._command_motion_detection = self.get_command_id(node['type']['endpoints'], "slot", "detection")
async def async_flip(entity):
entity._flip = not entity._flip
await entity.set_home_endpoint_value(entity._command_flip, {"value": entity._flip})
@property
def state_attributes(self):
"""Return the camera state attributes."""
attr = super().state_attributes
attr["motion_detection"] = self.motion_detection_enabled
attr["high_quality_video"] = self._high_quality_video
attr["flip_video"] = self._flip
attr["motion_threshold"] = self._motion_threshold
attr["motion_sensitivity"] = self._motion_sensitivity
attr["activation_with_alarm"] = self._activation_with_alarm
attr["timestamp"] = self._timestamp
attr["volume_microphone"] = self._volume_micro
attr["sound_detection"] = self._sound_detection
attr["sound_trigger"] = self._sound_trigger
attr["rtsp"] = self._rtsp
attr["disk"] = self._disk
return attr
@property
def motion_detection_enabled(self):
"""Return the camera motion detection status."""
return self._motion_detection_enabled
async def async_enable_motion_detection(self):
"""Enable motion detection in the camera."""
await self.set_home_endpoint_value(self._command_motion_detection, {"value": True})
self._motion_detection_enabled = True
async def async_disable_motion_detection(self):
"""Disable motion detection in camera."""
await self.set_home_endpoint_value(self._command_motion_detection, {"value": False})
self._motion_detection_enabled = False
@property
def supported_features(self):
"""Flag supported features."""
return self._supported_features
async def async_update(self):
"""Get the state & name and update it."""
self.update_parameters(self._router.nodes[self._id]);
@property
def should_poll(self):
"""Return True if entity has to be polled for state."""
return True
def update_parameters(self, node):
self._name = node["label"].strip()
# Get status
#if( node["status"] == "active"):
# self.is_streaming = True
#else:
# self.is_streaming = False
#self.is_recording?
# Parse all endpoints values & needed commands
for endpoint in filter(lambda x:(x["ep_type"] == "signal"), node['show_endpoints']):
if( endpoint["name"] == "detection" ):
self._motion_detection_enabled = endpoint["value"]
elif( endpoint["name"] == "activation" ):
self._activation_with_alarm = endpoint["value"]
elif( endpoint["name"] == "quality" ):
self._high_quality_video = endpoint["value"]
elif( endpoint["name"] == "sensitivity" ):
self._motion_sensitivity = endpoint["value"]
elif( endpoint["name"] == "threshold" ):
self._motion_threshold = endpoint["value"]
elif( endpoint["name"] == "flip" ):
self._flip = endpoint["value"]
elif( endpoint["name"] == "timestamp" ):
self._timestamp = endpoint["value"]
elif( endpoint["name"] == "volume" ):
self._volume_micro = endpoint["value"]
elif( endpoint["name"] == "sound_detection" ):
self._sound_detection = endpoint["value"]
elif( endpoint["name"] == "sound_trigger" ):
self._sound_trigger = endpoint["value"]
elif( endpoint["name"] == "rtsp" ):
self._rtsp = endpoint["value"]
elif( endpoint["name"] == "disk" ):
self._disk = endpoint["value"]