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: blacklight
GPG Key ID: D90FBA7F76362774
12 changed files with 50 additions and 103 deletions

View File

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

View File

@ -1,10 +1,11 @@
from sqlalchemy import Column, Integer, ForeignKey
from .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('Battery'):
if 'battery' not in Base.metadata:
class Battery(NumericSensor):
__tablename__ = 'battery'
@ -21,7 +22,3 @@ if not entity_types_registry.get('Battery'):
__mapper_args__ = {
'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 ._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):
__tablename__ = 'device'
@ -16,7 +18,3 @@ if not entity_types_registry.get('Device'):
__mapper_args__ = {
'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 .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):
__tablename__ = 'dimmer'
@ -19,7 +21,3 @@ if not entity_types_registry.get('Dimmer'):
__mapper_args__ = {
'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 .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('PowerSensor'):
if 'power_sensor' not in Base.metadata:
class PowerSensor(NumericSensor):
__tablename__ = 'power_sensor'
@ -17,12 +18,8 @@ if not entity_types_registry.get('PowerSensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['PowerSensor'] = PowerSensor
else:
PowerSensor = entity_types_registry['PowerSensor']
if not entity_types_registry.get('CurrentSensor'):
if 'current_sensor' not in Base.metadata:
class CurrentSensor(NumericSensor):
__tablename__ = 'current_sensor'
@ -35,12 +32,8 @@ if not entity_types_registry.get('CurrentSensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['CurrentSensor'] = CurrentSensor
else:
CurrentSensor = entity_types_registry['CurrentSensor']
if not entity_types_registry.get('VoltageSensor'):
if 'voltage_sensor' not in Base.metadata:
class VoltageSensor(NumericSensor):
__tablename__ = 'voltage_sensor'
@ -53,12 +46,8 @@ if not entity_types_registry.get('VoltageSensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['VoltageSensor'] = VoltageSensor
else:
VoltageSensor = entity_types_registry['VoltageSensor']
if not entity_types_registry.get('EnergySensor'):
if 'energy_sensor' not in Base.metadata:
class EnergySensor(NumericSensor):
__tablename__ = 'energy_sensor'
@ -70,7 +59,3 @@ if not entity_types_registry.get('EnergySensor'):
__mapper_args__ = {
'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 .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('HumiditySensor'):
if 'humidity_sensor' not in Base.metadata:
class HumiditySensor(NumericSensor):
__tablename__ = 'humidity_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('HumiditySensor'):
__mapper_args__ = {
'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 .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('IlluminanceSensor'):
if 'illuminance_sensor' not in Base.metadata:
class IlluminanceSensor(NumericSensor):
__tablename__ = 'illuminance_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('IlluminanceSensor'):
__mapper_args__ = {
'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 .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):
__tablename__ = 'light'
@ -18,6 +20,9 @@ if not entity_types_registry.get('Light'):
temperature = Column(Float)
x = Column(Float)
y = Column(Float)
red = Column(Float)
green = Column(Float)
blue = Column(Float)
colormode = Column(String)
effect = Column(String)
hue_min = Column(Float)
@ -32,7 +37,3 @@ if not entity_types_registry.get('Light'):
__mapper_args__ = {
'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 .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('LinkQuality'):
if 'link_quality' not in Base.metadata:
class LinkQuality(NumericSensor):
__tablename__ = 'link_quality'
@ -21,7 +22,3 @@ if not entity_types_registry.get('LinkQuality'):
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
entity_types_registry['LinkQuality'] = LinkQuality
else:
LinkQuality = entity_types_registry['LinkQuality']

View File

@ -10,7 +10,9 @@ from sqlalchemy import (
String,
)
from .devices import Device, entity_types_registry
from platypush.common.db import Base
from .devices import Device
logger = logging.getLogger(__name__)
@ -19,7 +21,7 @@ class Sensor(Device):
__abstract__ = True
if not entity_types_registry.get('RawSensor'):
if 'raw_sensor' not in Base.metadata:
class RawSensor(Sensor):
__tablename__ = 'raw_sensor'
@ -33,12 +35,8 @@ if not entity_types_registry.get('RawSensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['RawSensor'] = RawSensor
else:
RawSensor = entity_types_registry['RawSensor']
if not entity_types_registry.get('NumericSensor'):
if 'numeric_sensor' not in Base.metadata:
class NumericSensor(Sensor):
__tablename__ = 'numeric_sensor'
@ -55,12 +53,8 @@ if not entity_types_registry.get('NumericSensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['NumericSensor'] = NumericSensor
else:
NumericSensor = entity_types_registry['NumericSensor']
if not entity_types_registry.get('BinarySensor'):
if 'binary_sensor' not in Base.metadata:
class BinarySensor(Sensor):
__tablename__ = 'binary_sensor'
@ -88,12 +82,8 @@ if not entity_types_registry.get('BinarySensor'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['BinarySensor'] = BinarySensor
else:
BinarySensor = entity_types_registry['BinarySensor']
if not entity_types_registry.get('EnumSensor'):
if 'enum_sensor' not in Base.metadata:
class EnumSensor(Sensor):
__tablename__ = 'enum_sensor'
@ -107,7 +97,3 @@ if not entity_types_registry.get('EnumSensor'):
__mapper_args__ = {
'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 .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):
__tablename__ = 'switch'
@ -17,12 +19,8 @@ if not entity_types_registry.get('Switch'):
'polymorphic_identity': __tablename__,
}
entity_types_registry['Switch'] = Switch
else:
Switch = entity_types_registry['Switch']
if not entity_types_registry.get('EnumSwitch'):
if 'enum_switch' not in Base.metadata:
class EnumSwitch(Device):
__tablename__ = 'enum_switch'
@ -36,7 +34,3 @@ if not entity_types_registry.get('EnumSwitch'):
__mapper_args__ = {
'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 .devices import entity_types_registry
from platypush.common.db import Base
from .sensors import NumericSensor
if not entity_types_registry.get('TemperatureSensor'):
if 'temperature_sensor' not in Base.metadata:
class TemperatureSensor(NumericSensor):
__tablename__ = 'temperature_sensor'
@ -16,7 +17,3 @@ if not entity_types_registry.get('TemperatureSensor'):
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
entity_types_registry['TemperatureSensor'] = TemperatureSensor
else:
TemperatureSensor = entity_types_registry['TemperatureSensor']