alarms: refactor the alarms subsystem
also include eotk alarms now
This commit is contained in:
parent
a935055083
commit
e2ce24bf3b
17 changed files with 288 additions and 152 deletions
|
@ -1,7 +1,10 @@
|
|||
from abc import abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Union, List, Optional, Any
|
||||
|
||||
from app.alarms import alarms_for
|
||||
from app.extensions import db
|
||||
from app.models.alarms import Alarm
|
||||
|
||||
|
||||
class AbstractConfiguration(db.Model): # type: ignore
|
||||
|
@ -13,6 +16,15 @@ class AbstractConfiguration(db.Model): # type: ignore
|
|||
updated = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||
destroyed = db.Column(db.DateTime(), nullable=True)
|
||||
|
||||
@property
|
||||
def alarms(self) -> List[Alarm]:
|
||||
return alarms_for(self.brn)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def brn(self) -> str:
|
||||
raise NotImplementedError()
|
||||
|
||||
def destroy(self) -> None:
|
||||
self.destroyed = datetime.utcnow()
|
||||
self.updated = datetime.utcnow()
|
||||
|
@ -59,6 +71,11 @@ class AbstractResource(db.Model): # type: ignore
|
|||
if self.updated is None:
|
||||
self.updated = datetime.utcnow()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def brn(self) -> str:
|
||||
raise NotImplementedError()
|
||||
|
||||
def deprecate(self, *, reason: str) -> None:
|
||||
self.deprecated = datetime.utcnow()
|
||||
self.deprecation_reason = reason
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue