[system] Don't use is_defined macro for system plugin entities.

It seems to clash with something and cause plugin actions to return
random `ImportError`.
This commit is contained in:
Fabio Manganiello 2024-09-01 01:34:58 +02:00
parent 7cc7009d08
commit 9d086a4a10
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 206 additions and 244 deletions

View file

@ -1,289 +1,249 @@
from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, JSON, String
from platypush.common.db import is_defined
from . import Entity
from .devices import Device
from .sensors import NumericSensor, PercentSensor
from .temperature import TemperatureSensor
if not is_defined('cpu'):
class Cpu(Entity):
"""
``CPU`` ORM (container) model.
"""
class Cpu(Entity):
"""
``CPU`` ORM (container) model.
"""
__tablename__ = 'cpu'
__tablename__ = 'cpu'
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
percent = Column(Float)
percent = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class CpuInfo(Entity):
"""
``CpuInfo`` ORM model.
"""
if not is_defined('cpu_info'):
__tablename__ = 'cpu_info'
class CpuInfo(Entity):
"""
``CpuInfo`` ORM model.
"""
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
__tablename__ = 'cpu_info'
architecture = Column(String)
bits = Column(Integer)
cores = Column(Integer)
vendor = Column(String)
brand = Column(String)
frequency_advertised = Column(Integer)
frequency_actual = Column(Integer)
flags = Column(JSON)
l1_instruction_cache_size = Column(Integer)
l1_data_cache_size = Column(Integer)
l2_cache_size = Column(Integer)
l3_cache_size = Column(Integer)
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
architecture = Column(String)
bits = Column(Integer)
cores = Column(Integer)
vendor = Column(String)
brand = Column(String)
frequency_advertised = Column(Integer)
frequency_actual = Column(Integer)
flags = Column(JSON)
l1_instruction_cache_size = Column(Integer)
l1_data_cache_size = Column(Integer)
l2_cache_size = Column(Integer)
l3_cache_size = Column(Integer)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class CpuTimes(Entity):
"""
``CpuTimes`` ORM (container) model.
"""
__tablename__ = 'cpu_times'
if not is_defined('cpu_times'):
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
class CpuTimes(Entity):
"""
``CpuTimes`` ORM (container) model.
"""
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
__tablename__ = 'cpu_times'
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
class CpuStats(Entity):
"""
``CpuStats`` ORM (container) model.
"""
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
__tablename__ = 'cpu_stats'
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
if not is_defined('cpu_stats'):
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class CpuStats(Entity):
"""
``CpuStats`` ORM (container) model.
"""
__tablename__ = 'cpu_stats'
class MemoryStats(Entity):
"""
``MemoryStats`` ORM model.
"""
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__tablename__ = 'memory_stats'
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
total = Column(Integer)
available = Column(Integer)
used = Column(Integer)
free = Column(Integer)
active = Column(Integer)
inactive = Column(Integer)
buffers = Column(Integer)
cached = Column(Integer)
shared = Column(Integer)
percent = Column(Float)
if not is_defined('memory_stats'):
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class MemoryStats(Entity):
"""
``MemoryStats`` ORM model.
"""
__tablename__ = 'memory_stats'
class SwapStats(Entity):
"""
``SwapStats`` ORM model.
"""
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__tablename__ = 'swap_stats'
total = Column(Integer)
available = Column(Integer)
used = Column(Integer)
free = Column(Integer)
active = Column(Integer)
inactive = Column(Integer)
buffers = Column(Integer)
cached = Column(Integer)
shared = Column(Integer)
percent = Column(Float)
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
total = Column(Integer)
used = Column(Integer)
free = Column(Integer)
percent = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('swap_stats'):
class SwapStats(Entity):
"""
``SwapStats`` ORM model.
"""
class Disk(Entity):
"""
``Disk`` ORM model.
"""
__tablename__ = 'swap_stats'
__tablename__ = 'disk'
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
total = Column(Integer)
used = Column(Integer)
free = Column(Integer)
percent = Column(Float)
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
mountpoint = Column(String)
fstype = Column(String)
opts = Column(String)
total = Column(Integer)
used = Column(Integer)
free = Column(Integer)
percent = Column(Float)
read_count = Column(Integer)
write_count = Column(Integer)
read_bytes = Column(Integer)
write_bytes = Column(Integer)
read_time = Column(Float)
write_time = Column(Float)
busy_time = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('disk'):
class Disk(Entity):
"""
``Disk`` ORM model.
"""
class NetworkInterface(Device):
"""
``NetworkInterface`` ORM model.
"""
__tablename__ = 'disk'
__tablename__ = 'network_interface'
id = Column(
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
id = Column(Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True)
mountpoint = Column(String)
fstype = Column(String)
opts = Column(String)
total = Column(Integer)
used = Column(Integer)
free = Column(Integer)
percent = Column(Float)
read_count = Column(Integer)
write_count = Column(Integer)
read_bytes = Column(Integer)
write_bytes = Column(Integer)
read_time = Column(Float)
write_time = Column(Float)
busy_time = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('network_interface'):
class NetworkInterface(Device):
"""
``NetworkInterface`` ORM model.
"""
__tablename__ = 'network_interface'
id = Column(
Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True
)
bytes_sent = Column(Integer)
bytes_recv = Column(Integer)
packets_sent = Column(Integer)
packets_recv = Column(Integer)
errors_in = Column(Integer)
errors_out = Column(Integer)
drop_in = Column(Integer)
drop_out = Column(Integer)
addresses = Column(JSON)
speed = Column(Integer)
mtu = Column(Integer)
duplex = Column(String)
flags = Column(JSON)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('system_temperature'):
class SystemTemperature(TemperatureSensor):
"""
Extends the ``TemperatureSensor``.
"""
__tablename__ = 'system_temperature'
id = Column(
Integer,
ForeignKey(TemperatureSensor.id, ondelete='CASCADE'),
primary_key=True,
)
high = Column(Float)
critical = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('system_fan'):
class SystemFan(NumericSensor):
"""
``SystemFan`` ORM model.
"""
__tablename__ = 'system_fan'
id = Column(
Integer,
ForeignKey(NumericSensor.id, ondelete='CASCADE'),
primary_key=True,
)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
if not is_defined('system_battery'):
class SystemBattery(PercentSensor):
"""
``SystemBattery`` ORM model.
"""
__tablename__ = 'system_battery'
id = Column(
Integer,
ForeignKey(PercentSensor.id, ondelete='CASCADE'),
primary_key=True,
)
seconds_left = Column(Float)
power_plugged = Column(Boolean)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
bytes_sent = Column(Integer)
bytes_recv = Column(Integer)
packets_sent = Column(Integer)
packets_recv = Column(Integer)
errors_in = Column(Integer)
errors_out = Column(Integer)
drop_in = Column(Integer)
drop_out = Column(Integer)
addresses = Column(JSON)
speed = Column(Integer)
mtu = Column(Integer)
duplex = Column(String)
flags = Column(JSON)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class SystemTemperature(TemperatureSensor):
"""
Extends the ``TemperatureSensor``.
"""
__tablename__ = 'system_temperature'
id = Column(
Integer,
ForeignKey(TemperatureSensor.id, ondelete='CASCADE'),
primary_key=True,
)
high = Column(Float)
critical = Column(Float)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class SystemFan(NumericSensor):
"""
``SystemFan`` ORM model.
"""
__tablename__ = 'system_fan'
id = Column(
Integer,
ForeignKey(NumericSensor.id, ondelete='CASCADE'),
primary_key=True,
)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
class SystemBattery(PercentSensor):
"""
``SystemBattery`` ORM model.
"""
__tablename__ = 'system_battery'
id = Column(
Integer,
ForeignKey(PercentSensor.id, ondelete='CASCADE'),
primary_key=True,
)
seconds_left = Column(Float)
power_plugged = Column(Boolean)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}

View file

@ -634,13 +634,15 @@ class SystemPlugin(SensorPlugin, EntityManager):
if fan.get('id') and fan.get('label')
],
*[
SystemBattery(
id='system:battery',
name='Battery',
**battery,
(
SystemBattery(
id='system:battery',
name='Battery',
**battery,
)
if battery
else ()
)
if battery
else ()
],
]