import datetime
import divera.models
import divera.api.v1
from divera.api.v2.alarms import *
[docs]
class Alarm(divera.models.AlarmAndEvent):
def __init__(self,
id: int = None,
foreign_id: str = None,
author_id: int = None,
alarmcode_id: int = None,
date: [int, float, datetime.datetime] = None,
priority: bool = None,
title: str = None,
text: str = None,
address: str = None,
lat: float = None,
lng: float = None,
report: str = None,
cluster: list = None,
group: list = None,
user_cluster_relation: list = None,
vehicle: list = None,
private_mode: bool = None,
notification_type: int = None,
notification_filter_vehicle: bool = None,
notification_filter_status: bool = None,
notification_filter_access: bool = None,
response_time: [int, float, datetime.timedelta] = None,
closed: bool = None,
new: bool = None,
editable: bool = None,
answerable: bool = None,
hidden: bool = None,
deleted: bool = None,
ucr_answered: dict = None,
ucr_self_addressed: bool = None,
ucr_self_status_id: int = None,
ucr_self_note: str = None,
count_recipients: int = None,
count_read: int = None,
ts_response: [int, float, datetime.datetime] = None,
ts_publish: [int, float, datetime.datetime] = None,
ts_close: [int, float, datetime.datetime] = None,
ts_create: [int, float, datetime.datetime] = None,
ts_update: [int, float, datetime.datetime] = None,
notification_filter_status_access: bool = None,
cluster_id: int = None,
message_channel_id: int = None,
message_channel: bool = None,
custom_answers: bool = None,
attachment_count: int = None,
duration: str = None,
ucr_addressed: list = None,
ucr_answeredcount: dict = None,
ucr_read: list = None,
notification_filter_shift_plan: int = None,
data: dict = None,
):
super().__init__(
data={
**{
'id': id,
'foreign_id': foreign_id,
'author_id': author_id,
'alarmcode_id': alarmcode_id,
'date': date.timestamp() if type(date) is datetime.datetime else date,
'priority': priority,
'title': title,
'text': text,
'address': address,
'lat': lat,
'lng': lng,
'report': report,
'cluster': cluster,
'group': group,
'user_cluster_relation': user_cluster_relation,
'vehicle': vehicle,
'private_mode': private_mode,
'notification_type': notification_type,
'notification_filter_vehicle': notification_filter_vehicle,
'notification_filter_status': notification_filter_status,
'notification_filter_access': notification_filter_access,
'response_time': response_time.total_seconds()
if type(response_time) is datetime.timedelta else
response_time,
'closed': closed,
'new': new,
'editable': editable,
'answerable': answerable,
'hidden': hidden,
'deleted': deleted,
'ucr_answered': ucr_answered,
'ucr_self_addressed': ucr_self_addressed,
'ucr_self_status_id': ucr_self_status_id,
'ucr_self_note': ucr_self_note,
'count_recipients': count_recipients,
'count_read': count_read,
'ts_response': ts_response.timestamp() if type(ts_response) is datetime.datetime else ts_response,
'ts_publish': ts_publish.timestamp() if type(ts_publish) is datetime.datetime else ts_publish,
'ts_close': ts_close.timestamp() if type(ts_close) is datetime.datetime else ts_close,
'ts_create': ts_create.timestamp() if type(ts_create) is datetime.datetime else ts_create,
'ts_update': ts_update.timestamp() if type(ts_update) is datetime.datetime else ts_update,
'notification_filter_status_access': notification_filter_status_access,
'cluster_id': cluster_id,
'message_channel_id': message_channel_id,
'message_channel': message_channel,
'custom_answers': custom_answers,
'attachment_count': attachment_count,
'duration': duration,
'ucr_addressed': ucr_addressed,
'ucr_answeredcount': ucr_answeredcount,
'ucr_read': ucr_read,
'notification_filter_shift_plan': notification_filter_shift_plan,
},
**(data or {})
},
)
@property
def alarmcode_id(self) -> int:
return self.data['alarmcode_id']
@property
def priority(self) -> bool:
return self.data['priority']
@property
def report(self) -> str:
return self.data['report']
@property
def vehicle(self) -> list:
return self.data['vehicle']
@property
def notification_filter_vehicle(self) -> bool:
return self.data['notification_filter_vehicle']
@property
def notification_filter_status(self) -> bool:
return self.data['notification_filter_status']
@property
def notification_filter_access(self) -> bool:
return self.data['notification_filter_access']
@property
def response_time(self) -> datetime.timedelta:
if self.data['response_time'] is not None:
return datetime.timedelta(seconds=self.data['response_time'])
@property
def closed(self) -> bool:
return self.data['closed']
@property
def ucr_answered(self) -> dict:
return self.data['ucr_answered']
@property
def ucr_self_status_id(self) -> int:
return self.data['ucr_self_status_id']
@property
def ucr_self_note(self) -> str:
return self.data['ucr_self_note']
@property
def ts_close(self) -> datetime.datetime:
return self.data['ts_close']
@property
def notification_filter_status_access(self) -> bool:
return self.data['notification_filter_status_access']
@property
def duration(self) -> str:
return self.data['duration']
@property
def ucr_answeredcount(self) -> dict:
return self.data['ucr_answeredcount']
@property
def notification_filter_shift_plan(self) -> int:
return self.data['notification_filter_shift_plan']
[docs]
@staticmethod
def get_all(
):
request = divera.api.v2.alarms.GetAll(
)
request.process_result = lambda result: [Alarm(data=r) for r in list((result['data']['items'] or {}).values())]
return request
[docs]
def get(
self,
object_id: str = None,
):
request = Get(
object_id=object_id or self.id,
)
request.process_result = lambda result: Alarm(data=result['data'])
return request
[docs]
def confirm(
self,
response_id: str,
response_text: str = None,
):
request = divera.api.v1.Confirm(
alarm_id=self.id,
status_id=response_id,
note=response_text,
)
return request
[docs]
def read(
self,
object_id: str = None,
):
request = Read(
object_id=object_id or self.id,
)
return request