Check for table metadata existance in Base.metadata instead of having a separate entity registry

This commit is contained in:
Fabio Manganiello 2022-12-04 16:27:28 +01:00
parent 1ab85f99d9
commit ecba72935f
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
12 changed files with 50 additions and 103 deletions

View file

@ -8,7 +8,7 @@
</div> </div>
<div class="col-1 right"> <div class="col-1 right">
<button title="Refresh" @click="refresh(null)"> <button title="Refresh" @click="refresh">
<i class="fa fa-sync-alt" /> <i class="fa fa-sync-alt" />
</button> </button>
</div> </div>
@ -16,7 +16,7 @@
<div class="groups-canvas"> <div class="groups-canvas">
<EntityModal :entity="entities[modalEntityId]" <EntityModal :entity="entities[modalEntityId]"
:visible="modalVisible" @close="onEntityModal(null)" :visible="modalVisible" @close="onEntityModal"
v-if="modalEntityId" v-if="modalEntityId"
/> />

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('Battery'): if 'battery' not in Base.metadata:
class Battery(NumericSensor): class Battery(NumericSensor):
__tablename__ = 'battery' __tablename__ = 'battery'
@ -21,7 +22,3 @@ if not entity_types_registry.get('Battery'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['Battery'] = Battery
else:
Battery = entity_types_registry['Battery']

View file

@ -1,9 +1,11 @@
from sqlalchemy import Column, Integer, Boolean, ForeignKey from sqlalchemy import Column, Integer, Boolean, ForeignKey
from ._base import Entity, entity_types_registry from platypush.common.db import Base
from ._base import Entity
if not entity_types_registry.get('Device'): if 'device' not in Base.metadata:
class Device(Entity): class Device(Entity):
__tablename__ = 'device' __tablename__ = 'device'
@ -16,7 +18,3 @@ if not entity_types_registry.get('Device'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['Device'] = Device
else:
Device = entity_types_registry['Device']

View file

@ -1,9 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey, Float from sqlalchemy import Column, Integer, ForeignKey, Float
from .devices import Device, entity_types_registry from platypush.common.db import Base
from .devices import Device
if not entity_types_registry.get('Dimmer'): if 'dimmer' not in Base.metadata:
class Dimmer(Device): class Dimmer(Device):
__tablename__ = 'dimmer' __tablename__ = 'dimmer'
@ -19,7 +21,3 @@ if not entity_types_registry.get('Dimmer'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['Dimmer'] = Dimmer
else:
Dimmer = entity_types_registry['Dimmer']

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('PowerSensor'): if 'power_sensor' not in Base.metadata:
class PowerSensor(NumericSensor): class PowerSensor(NumericSensor):
__tablename__ = 'power_sensor' __tablename__ = 'power_sensor'
@ -17,12 +18,8 @@ if not entity_types_registry.get('PowerSensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['PowerSensor'] = PowerSensor
else:
PowerSensor = entity_types_registry['PowerSensor']
if 'current_sensor' not in Base.metadata:
if not entity_types_registry.get('CurrentSensor'):
class CurrentSensor(NumericSensor): class CurrentSensor(NumericSensor):
__tablename__ = 'current_sensor' __tablename__ = 'current_sensor'
@ -35,12 +32,8 @@ if not entity_types_registry.get('CurrentSensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['CurrentSensor'] = CurrentSensor
else:
CurrentSensor = entity_types_registry['CurrentSensor']
if 'voltage_sensor' not in Base.metadata:
if not entity_types_registry.get('VoltageSensor'):
class VoltageSensor(NumericSensor): class VoltageSensor(NumericSensor):
__tablename__ = 'voltage_sensor' __tablename__ = 'voltage_sensor'
@ -53,12 +46,8 @@ if not entity_types_registry.get('VoltageSensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['VoltageSensor'] = VoltageSensor
else:
VoltageSensor = entity_types_registry['VoltageSensor']
if 'energy_sensor' not in Base.metadata:
if not entity_types_registry.get('EnergySensor'):
class EnergySensor(NumericSensor): class EnergySensor(NumericSensor):
__tablename__ = 'energy_sensor' __tablename__ = 'energy_sensor'
@ -70,7 +59,3 @@ if not entity_types_registry.get('EnergySensor'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['EnergySensor'] = EnergySensor
else:
EnergySensor = entity_types_registry['EnergySensor']

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('HumiditySensor'): if 'humidity_sensor' not in Base.metadata:
class HumiditySensor(NumericSensor): class HumiditySensor(NumericSensor):
__tablename__ = 'humidity_sensor' __tablename__ = 'humidity_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('HumiditySensor'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['HumiditySensor'] = HumiditySensor
else:
HumiditySensor = entity_types_registry['HumiditySensor']

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('IlluminanceSensor'): if 'illuminance_sensor' not in Base.metadata:
class IlluminanceSensor(NumericSensor): class IlluminanceSensor(NumericSensor):
__tablename__ = 'illuminance_sensor' __tablename__ = 'illuminance_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('IlluminanceSensor'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['IlluminanceSensor'] = IlluminanceSensor
else:
IlluminanceSensor = entity_types_registry['IlluminanceSensor']

View file

@ -1,9 +1,11 @@
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, Float from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, Float
from .devices import Device, entity_types_registry from platypush.common.db import Base
from .devices import Device
if not entity_types_registry.get('Light'): if 'light' not in Base.metadata:
class Light(Device): class Light(Device):
__tablename__ = 'light' __tablename__ = 'light'
@ -18,6 +20,9 @@ if not entity_types_registry.get('Light'):
temperature = Column(Float) temperature = Column(Float)
x = Column(Float) x = Column(Float)
y = Column(Float) y = Column(Float)
red = Column(Float)
green = Column(Float)
blue = Column(Float)
colormode = Column(String) colormode = Column(String)
effect = Column(String) effect = Column(String)
hue_min = Column(Float) hue_min = Column(Float)
@ -32,7 +37,3 @@ if not entity_types_registry.get('Light'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['Light'] = Light
else:
Light = entity_types_registry['Light']

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('LinkQuality'): if 'link_quality' not in Base.metadata:
class LinkQuality(NumericSensor): class LinkQuality(NumericSensor):
__tablename__ = 'link_quality' __tablename__ = 'link_quality'
@ -21,7 +22,3 @@ if not entity_types_registry.get('LinkQuality'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['LinkQuality'] = LinkQuality
else:
LinkQuality = entity_types_registry['LinkQuality']

View file

@ -10,7 +10,9 @@ from sqlalchemy import (
String, String,
) )
from .devices import Device, entity_types_registry from platypush.common.db import Base
from .devices import Device
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -19,7 +21,7 @@ class Sensor(Device):
__abstract__ = True __abstract__ = True
if not entity_types_registry.get('RawSensor'): if 'raw_sensor' not in Base.metadata:
class RawSensor(Sensor): class RawSensor(Sensor):
__tablename__ = 'raw_sensor' __tablename__ = 'raw_sensor'
@ -33,12 +35,8 @@ if not entity_types_registry.get('RawSensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['RawSensor'] = RawSensor
else:
RawSensor = entity_types_registry['RawSensor']
if 'numeric_sensor' not in Base.metadata:
if not entity_types_registry.get('NumericSensor'):
class NumericSensor(Sensor): class NumericSensor(Sensor):
__tablename__ = 'numeric_sensor' __tablename__ = 'numeric_sensor'
@ -55,12 +53,8 @@ if not entity_types_registry.get('NumericSensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['NumericSensor'] = NumericSensor
else:
NumericSensor = entity_types_registry['NumericSensor']
if 'binary_sensor' not in Base.metadata:
if not entity_types_registry.get('BinarySensor'):
class BinarySensor(Sensor): class BinarySensor(Sensor):
__tablename__ = 'binary_sensor' __tablename__ = 'binary_sensor'
@ -88,12 +82,8 @@ if not entity_types_registry.get('BinarySensor'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['BinarySensor'] = BinarySensor
else:
BinarySensor = entity_types_registry['BinarySensor']
if 'enum_sensor' not in Base.metadata:
if not entity_types_registry.get('EnumSensor'):
class EnumSensor(Sensor): class EnumSensor(Sensor):
__tablename__ = 'enum_sensor' __tablename__ = 'enum_sensor'
@ -107,7 +97,3 @@ if not entity_types_registry.get('EnumSensor'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['EnumSensor'] = EnumSensor
else:
EnumSensor = entity_types_registry['EnumSensor']

View file

@ -1,9 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey, Boolean, String, JSON from sqlalchemy import Column, Integer, ForeignKey, Boolean, String, JSON
from .devices import Device, entity_types_registry from platypush.common.db import Base
from .devices import Device
if not entity_types_registry.get('Switch'): if 'switch' not in Base.metadata:
class Switch(Device): class Switch(Device):
__tablename__ = 'switch' __tablename__ = 'switch'
@ -17,12 +19,8 @@ if not entity_types_registry.get('Switch'):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['Switch'] = Switch
else:
Switch = entity_types_registry['Switch']
if 'enum_switch' not in Base.metadata:
if not entity_types_registry.get('EnumSwitch'):
class EnumSwitch(Device): class EnumSwitch(Device):
__tablename__ = 'enum_switch' __tablename__ = 'enum_switch'
@ -36,7 +34,3 @@ if not entity_types_registry.get('EnumSwitch'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['EnumSwitch'] = EnumSwitch
else:
EnumSwitch = entity_types_registry['EnumSwitch']

View file

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry from platypush.common.db import Base
from .sensors import NumericSensor from .sensors import NumericSensor
if not entity_types_registry.get('TemperatureSensor'): if 'temperature_sensor' not in Base.metadata:
class TemperatureSensor(NumericSensor): class TemperatureSensor(NumericSensor):
__tablename__ = 'temperature_sensor' __tablename__ = 'temperature_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('TemperatureSensor'):
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
entity_types_registry['TemperatureSensor'] = TemperatureSensor
else:
TemperatureSensor = entity_types_registry['TemperatureSensor']