class Client(db.Model): ''' Model for storing data about devices ''' __tablename__ = 'clients' id = db.Column(db.Integer, primary_key=True) client_uuid = db.Column(db.String, nullable=False, unique=True) client = db.Column(db.String(50), nullable=True) tokens = db.relationship('JWTBeacon', backref='client', lazy='dynamic') identity_id = db.Column(db.Integer, db.ForeignKey('identity.id'), nullable=True)
class JWTBeacon(JWToken): ''' Model for storing JWT authorization tokens. ''' client_id = db.Column(db.String, db.ForeignKey('clients.client_uuid'), nullable=True) def to_dict(self): return { 'id': self.id, 'jti': self.jti, 'token_type': self.token_type, 'client_id': self.client_id, 'expires': self.expires, 'revoked': self.revoked }
class WSState(db.Model): __tablename__ = 'WSState' id = db.Column(db.Integer, primary_key=True) idx = db.Column(db.Integer, nullable=True) name = db.Column(db.String(30), nullable=False) state_type = db.Column(db.String(100), nullable=True) description = db.Column(db.String(500), nullable=True) value = db.Column(db.String(100), nullable=True) device_id = db.Column(db.Integer, db.ForeignKey('wsdevices.id'), nullable=True) def to_dict(self): return { 'id': self.id, 'name': self.name, 'description': self.description, 'value': self.value, 'state_type': self.state_type, }
class WSCommand(db.Model): __tablename__ = 'wscommands' id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(300), nullable=False) name = db.Column(db.String(30), nullable=False) event = db.Column(db.String(30), nullable=False) json_command = db.Column(JSONType, nullable=True) device_id = db.Column(db.Integer, db.ForeignKey('wsdevices.id'), nullable=True) def to_dict(self) -> dict: return { 'id': self.id, 'name': self.name, 'description': self.description, 'event': self.event, 'json_command': self.json_command, 'device_id': self.device_id, }
from google.oauth2.credentials import Credentials from automoticz.extensions import db scopes_m2m = db.Table( 'scopes', db.Column( 'scope_id', db.Integer, db.ForeignKey('oauth2_scopes.id'), primary_key=True), db.Column( 'credential_id', db.Integer, db.ForeignKey('oauth2_credentials.id'), primary_key=True), ) class OAuth2Scope(db.Model): ''' Google OAuth2 scope for resource ''' __tablename__ = 'oauth2_scopes' id = db.Column(db.Integer, primary_key=True) scope = db.Column(db.String(100), unique=True, nullable=False) @classmethod def from_scope(cls, scope): ''' Create OAuth2Scope model object if not exists