1 """Support for Agent camera streaming."""
3 from datetime
import timedelta
6 from agent
import AgentError
14 async_get_current_platform,
17 from .
import AgentDVRConfigEntry
18 from .const
import ATTRIBUTION, CAMERA_SCAN_INTERVAL_SECS, DOMAIN
as AGENT_DOMAIN
20 SCAN_INTERVAL =
timedelta(seconds=CAMERA_SCAN_INTERVAL_SECS)
22 _LOGGER = logging.getLogger(__name__)
24 _DEV_EN_ALT =
"enable_alerts"
25 _DEV_DS_ALT =
"disable_alerts"
26 _DEV_EN_REC =
"start_recording"
27 _DEV_DS_REC =
"stop_recording"
28 _DEV_SNAP =
"snapshot"
31 _DEV_EN_ALT:
"async_enable_alerts",
32 _DEV_DS_ALT:
"async_disable_alerts",
33 _DEV_EN_REC:
"async_start_recording",
34 _DEV_DS_REC:
"async_stop_recording",
35 _DEV_SNAP:
"async_snapshot",
41 config_entry: AgentDVRConfigEntry,
42 async_add_entities: AddEntitiesCallback,
44 """Set up the Agent cameras."""
48 server = config_entry.runtime_data
49 if not server.devices:
50 _LOGGER.warning(
"Could not fetch cameras from Agent server")
53 for device
in server.devices:
54 if device.typeID == 2:
56 cameras.append(camera)
61 for service, method
in CAMERA_SERVICES.items():
62 platform.async_register_entity_service(service,
None, method)
66 """Representation of an Agent Device Stream."""
68 _attr_attribution = ATTRIBUTION
69 _attr_should_poll =
True
70 _attr_supported_features = CameraEntityFeature.ON_OFF
71 _attr_has_entity_name =
True
75 """Initialize as a subclass of MjpegCamera."""
78 self.
_attr_unique_id_attr_unique_id = f
"{device.client.unique}_{device.typeID}_{device.id}"
81 mjpeg_url=f
"{device.client._server_url}{device.mjpeg_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
82 still_image_url=f
"{device.client._server_url}{device.still_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
85 identifiers={(AGENT_DOMAIN, self.unique_id)},
88 name=f
"{device.client.name} {device.name}",
89 sw_version=device.client.version,
93 """Update our state from the Agent API."""
97 _LOGGER.debug(
"%s reacquired", self.name)
101 if self.
devicedevice.client.is_available
and not self.
_removed_removed:
102 _LOGGER.error(
"%s lost", self.name)
110 "enabled": self.
is_onis_on,
114 "has_ptz": self.
devicedevice.has_ptz,
115 "alerts_enabled": self.
devicedevice.alerts_active,
120 """Return whether the monitor is recording."""
121 return self.
devicedevice.recording
125 """Return whether the monitor has alerted."""
126 return self.
devicedevice.alerted
130 """Return whether the monitor has alerted."""
131 return self.
devicedevice.detected
135 """Return True if entity is connected."""
136 return self.
devicedevice.connected
140 """Return true if on."""
141 return self.
devicedevice.online
145 """Return the camera motion detection status."""
146 return self.
devicedevice.detector_active
150 await self.
devicedevice.alerts_on()
153 """Disable alerts."""
154 await self.
devicedevice.alerts_off()
157 """Enable motion detection."""
158 await self.
devicedevice.detector_on()
161 """Disable motion detection."""
162 await self.
devicedevice.detector_off()
165 """Start recording."""
166 await self.
devicedevice.record()
169 """Stop recording."""
170 await self.
devicedevice.record_stop()
173 """Enable the camera."""
177 """Take a snapshot."""
178 await self.
devicedevice.snapshot()
181 """Disable the camera."""
def async_start_recording(self)
None async_disable_motion_detection(self)
def async_stop_recording(self)
_attr_extra_state_attributes
def async_enable_alerts(self)
None async_turn_off(self)
def __init__(self, device)
def async_disable_alerts(self)
bool motion_detection_enabled(self)
None async_enable_motion_detection(self)
None async_setup_entry(HomeAssistant hass, AgentDVRConfigEntry config_entry, AddEntitiesCallback async_add_entities)
IssData update(pyiss.ISS iss)
None filter_urllib3_logging()