Пример #1
0
    def update(self):
        """Update the sensor."""
        event = zoneminder.get_state(
            'api/events/index/MonitorId:%i.json' % self._monitor_id
        )

        self._state = event['pagination']['count']
Пример #2
0
 def update(self):
     """Update the switch value."""
     monitor = zoneminder.get_state(
         'api/monitors/%i.json' % self._monitor_id
     )
     current_state = monitor['monitor']['Monitor']['Function']
     self._state = True if current_state == self._on_state else False
Пример #3
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Setup ZoneMinder cameras."""
    cameras = []
    monitors = zoneminder.get_state('api/monitors.json')
    if not monitors:
        _LOGGER.warning('Could not fetch monitors from ZoneMinder')
        return

    for i in monitors['monitors']:
        monitor = i['Monitor']

        if monitor['Function'] == 'None':
            _LOGGER.info('Skipping camera %s', monitor['Id'])
            continue

        _LOGGER.info('Initializing camera %s', monitor['Id'])

        device_info = {
            CONF_NAME: monitor['Name'],
            CONF_MJPEG_URL: _get_image_url(hass, monitor, 'jpeg'),
            CONF_STILL_IMAGE_URL: _get_image_url(hass, monitor, 'single')
        }
        cameras.append(MjpegCamera(hass, device_info))

    if not cameras:
        _LOGGER.warning('No active cameras found')
        return

    async_add_devices(cameras)
Пример #4
0
    def update(self):
        """Update the sensor."""
        event = zoneminder.get_state(
            'api/events/index/MonitorId:%i.json' % self._monitor_id
        )

        self._state = event['pagination']['count']
Пример #5
0
 def update(self):
     """Update the sensor."""
     monitor = zoneminder.get_state("api/monitors/%i.json" % self._monitor_id)
     if monitor["monitor"]["Monitor"]["Function"] is None:
         self._state = STATE_UNKNOWN
     else:
         self._state = monitor["monitor"]["Monitor"]["Function"]
Пример #6
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Setup ZoneMinder cameras."""
    cameras = []
    monitors = zoneminder.get_state('api/monitors.json')
    if not monitors:
        _LOGGER.warning('Could not fetch monitors from ZoneMinder')
        return

    for i in monitors['monitors']:
        monitor = i['Monitor']

        if monitor['Function'] == 'None':
            _LOGGER.info('Skipping camera %s', monitor['Id'])
            continue

        _LOGGER.info('Initializing camera %s', monitor['Id'])

        device_info = {
            CONF_NAME: monitor['Name'],
            CONF_MJPEG_URL: _get_image_url(hass, monitor, 'jpeg'),
            CONF_STILL_IMAGE_URL: _get_image_url(hass, monitor, 'single')
        }
        cameras.append(MjpegCamera(hass, device_info))

    if not cameras:
        _LOGGER.warning('No active cameras found')
        return

    async_add_devices(cameras)
Пример #7
0
 def update(self):
     """Update the sensor."""
     monitor = zoneminder.get_state('api/monitors/%i.json' %
                                    self._monitor_id)
     if monitor['monitor']['Monitor']['Function'] is None:
         self._state = STATE_UNKNOWN
     else:
         self._state = monitor['monitor']['Monitor']['Function']
Пример #8
0
    def update(self):
        """Update the sensor."""
        archived_filter = "/Archived:0"
        if self._include_archived:
            archived_filter = ""

        event = zoneminder.get_state("api/events/index/MonitorId:%i%s.json" % (self._monitor_id, archived_filter))

        self._state = event["pagination"]["count"]
Пример #9
0
 def update(self):
     """Update the sensor."""
     monitor = zoneminder.get_state(
         'api/monitors/%i.json' % self._monitor_id
     )
     if monitor['monitor']['Monitor']['Function'] is None:
         self._state = STATE_UNKNOWN
     else:
         self._state = monitor['monitor']['Monitor']['Function']
Пример #10
0
    def update(self):
        """Update the sensor."""
        archived_filter = '/Archived:0'
        if self._include_archived:
            archived_filter = ''

        event = zoneminder.get_state('api/events/index/MonitorId:%i%s.json' %
                                     (self._monitor_id, archived_filter))

        self._state = event['pagination']['count']
Пример #11
0
    def update(self):
        """Update our recording state from the ZM API."""
        _LOGGER.debug('Updating camera state for monitor %i', self._monitor_id)
        status_response = zoneminder.get_state(
            'api/monitors/alarm/id:%i/command:status.json' % self._monitor_id)
        if not status_response:
            _LOGGER.warning('Could not get status for monitor %i',
                            self._monitor_id)
            return

        self._is_recording = status_response['status'] == ZM_STATE_ALARM
Пример #12
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder sensor platform."""
    sensors = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        sensors.append(
            ZMSensorMonitors(int(i['Monitor']['Id']), i['Monitor']['Name']))
        sensors.append(
            ZMSensorEvents(int(i['Monitor']['Id']), i['Monitor']['Name']))

    add_devices(sensors)
Пример #13
0
    def update(self):
        """Update the sensor."""
        archived_filter = '/Archived:0'
        if self._include_archived:
            archived_filter = ''

        event = zoneminder.get_state(
            'api/events/index/MonitorId:%i%s.json' % (self._monitor_id,
                                                      archived_filter)
        )

        self._state = event['pagination']['count']
Пример #14
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder switch platform."""
    on_state = config.get(CONF_COMMAND_ON)
    off_state = config.get(CONF_COMMAND_OFF)

    switches = []

    monitors = zoneminder.get_state("api/monitors.json")
    for i in monitors["monitors"]:
        switches.append(ZMSwitchMonitors(int(i["Monitor"]["Id"]), i["Monitor"]["Name"], on_state, off_state))

    add_devices(switches)
Пример #15
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder sensor platform."""
    include_archived = config.get(CONF_INCLUDE_ARCHIVED)

    sensors = []

    monitors = zoneminder.get_state("api/monitors.json")
    for i in monitors["monitors"]:
        sensors.append(ZMSensorMonitors(int(i["Monitor"]["Id"]), i["Monitor"]["Name"]))
        sensors.append(ZMSensorEvents(int(i["Monitor"]["Id"]), i["Monitor"]["Name"], include_archived))

    add_devices(sensors)
Пример #16
0
    def update(self):
        """Update our recording state from the ZM API."""
        _LOGGER.debug('Updating camera state for monitor %i', self._monitor_id)
        status_response = zoneminder.get_state(
            'api/monitors/alarm/id:%i/command:status.json' % self._monitor_id
        )
        if not status_response:
            _LOGGER.warning('Could not get status for monitor %i',
                            self._monitor_id)
            return

        self._is_recording = status_response['status'] == ZM_STATE_ALARM
Пример #17
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Zoneminder switch."""
    on_state = config.get(CONF_COMMAND_ON)
    off_state = config.get(CONF_COMMAND_OFF)

    switches = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        switches.append(
            ZMSwitchMonitors(int(i['Monitor']['Id']), i['Monitor']['Name'],
                             on_state, off_state))

    add_devices(switches)
Пример #18
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder sensor platform."""
    sensors = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        sensors.append(
            ZMSensorMonitors(int(i['Monitor']['Id']), i['Monitor']['Name'])
        )
        sensors.append(
            ZMSensorEvents(int(i['Monitor']['Id']), i['Monitor']['Name'])
        )

    add_devices(sensors)
Пример #19
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder sensor platform."""
    include_archived = config.get(CONF_INCLUDE_ARCHIVED)

    sensors = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        sensors.append(
            ZMSensorMonitors(int(i['Monitor']['Id']), i['Monitor']['Name']))
        sensors.append(
            ZMSensorEvents(int(i['Monitor']['Id']), i['Monitor']['Name'],
                           include_archived))

    add_devices(sensors)
Пример #20
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder sensor platform."""
    include_archived = config.get(CONF_INCLUDE_ARCHIVED)

    sensors = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        sensors.append(
            ZMSensorMonitors(int(i['Monitor']['Id']), i['Monitor']['Name'])
        )
        sensors.append(
            ZMSensorEvents(int(i['Monitor']['Id']), i['Monitor']['Name'],
                           include_archived)
        )

    add_devices(sensors)
Пример #21
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ZoneMinder switch platform."""
    on_state = config.get(CONF_COMMAND_ON)
    off_state = config.get(CONF_COMMAND_OFF)

    switches = []

    monitors = zoneminder.get_state('api/monitors.json')
    for i in monitors['monitors']:
        switches.append(
            ZMSwitchMonitors(
                int(i['Monitor']['Id']),
                i['Monitor']['Name'],
                on_state,
                off_state
            )
        )

    add_devices(switches)
Пример #22
0
    def update(self):
        """Update the sensor."""
        date_filter = '1%20{}'.format(self._type)
        if self._type == 'all':
            # The consoleEvents API uses DATE_SUB, so give it
            # something large
            date_filter = '100%20year'

        archived_filter = '/Archived=:0'
        if self._include_archived:
            archived_filter = ''

        event = zoneminder.get_state(
            'api/events/consoleEvents/{}{}.json'.format(
                date_filter, archived_filter))

        try:
            self._state = event['results'][str(self._monitor_id)]
        except (TypeError, KeyError):
            self._state = '0'
Пример #23
0
    def update(self):
        """Update the sensor."""
        date_filter = '1%20{}'.format(self._type)
        if self._type == 'all':
            # The consoleEvents API uses DATE_SUB, so give it
            # something large
            date_filter = '100%20year'

        archived_filter = '/Archived=:0'
        if self._include_archived:
            archived_filter = ''

        event = zoneminder.get_state(
            'api/events/consoleEvents/{}{}.json'.format(date_filter,
                                                        archived_filter)
        )

        try:
            self._state = event['results'][str(self._monitor_id)]
        except (TypeError, KeyError):
            self._state = '0'
Пример #24
0
 def update(self):
     """Update the switch value."""
     monitor = zoneminder.get_state('api/monitors/%i.json' %
                                    self._monitor_id)
     current_state = monitor['monitor']['Monitor']['Function']
     self._state = True if current_state == self._on_state else False
Пример #25
0
 def update(self):
     """Update the switch value."""
     monitor = zoneminder.get_state("api/monitors/%i.json" % self._monitor_id)
     current_state = monitor["monitor"]["Monitor"]["Function"]
     self._state = True if current_state == self._on_state else False