# coding=utf-8
import json
from datetime import datetime
from homematicip.base.homematicip_object import HomeMaticIPObject
[docs]
class SecurityEvent(HomeMaticIPObject):
"""this class represents a security event """
def __init__(self, connection):
super().__init__(connection)
self.eventTimestamp = None
self.eventType = None
self.label = None
[docs]
def from_json(self, js):
super().from_json(js)
self.label = js["label"]
time = js["eventTimestamp"]
if time > 0:
self.eventTimestamp = datetime.fromtimestamp(time / 1000.0)
else:
self.eventTimestamp = None
self.eventType = js["eventType"]
def __str__(self):
return "{} {} {}".format(
self.eventType,
self.label,
self.eventTimestamp.strftime("%Y.%m.%d %H:%M:%S"),
)
[docs]
class SecurityZoneEvent(SecurityEvent):
""" This class will be used by other events which are just adding "securityZoneValues" """
def __init__(self, connection):
super().__init__(connection)
self.external_zone = None
self.internal_zone = None
[docs]
def from_json(self, js):
super().from_json(js)
self.external_zone = js["securityZoneValues"]["EXTERNAL"]
self.internal_zone = js["securityZoneValues"]["INTERNAL"]
def __str__(self):
return "{} external_zone({}) internal_zone({}) ".format(
super().__str__(), self.external_zone, self.internal_zone
)
[docs]
class SensorEvent(SecurityEvent):
pass
[docs]
class AccessPointDisconnectedEvent(SecurityEvent):
pass
[docs]
class AccessPointConnectedEvent(SecurityEvent):
pass
[docs]
class ActivationChangedEvent(SecurityZoneEvent):
pass
[docs]
class SilenceChangedEvent(SecurityZoneEvent):
pass
[docs]
class SabotageEvent(SecurityEvent):
pass
[docs]
class MoistureDetectionEvent(SecurityEvent):
pass
[docs]
class SmokeAlarmEvent(SecurityEvent):
pass
[docs]
class ExternalTriggeredEvent(SecurityEvent):
pass
[docs]
class OfflineAlarmEvent(SecurityEvent):
pass
[docs]
class WaterDetectionEvent(SecurityEvent):
pass
[docs]
class MainsFailureEvent(SecurityEvent):
pass
[docs]
class OfflineWaterDetectionEvent(SecurityEvent):
pass