[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 sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, JSON, String
from platypush.common.db import is_defined
from . import Entity from . import Entity
from .devices import Device from .devices import Device
from .sensors import NumericSensor, PercentSensor from .sensors import NumericSensor, PercentSensor
from .temperature import TemperatureSensor from .temperature import TemperatureSensor
if not is_defined('cpu'): class Cpu(Entity):
"""
``CPU`` ORM (container) model.
"""
class Cpu(Entity): __tablename__ = 'cpu'
"""
``CPU`` ORM (container) model.
"""
__tablename__ = 'cpu' id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
id = Column( percent = Column(Float)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
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): id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
"""
``CpuInfo`` ORM model.
"""
__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( __table_args__ = {'extend_existing': True}
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=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} class CpuTimes(Entity):
__mapper_args__ = { """
'polymorphic_identity': __tablename__, ``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): __table_args__ = {'extend_existing': True}
""" __mapper_args__ = {
``CpuTimes`` ORM (container) model. 'polymorphic_identity': __tablename__,
""" }
__tablename__ = 'cpu_times'
id = Column( class CpuStats(Entity):
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True """
) ``CpuStats`` ORM (container) model.
"""
__table_args__ = {'extend_existing': True} __tablename__ = 'cpu_stats'
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
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( __tablename__ = 'memory_stats'
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__table_args__ = {'extend_existing': True} id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}
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( __tablename__ = 'swap_stats'
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
total = Column(Integer) id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
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)
__table_args__ = {'extend_existing': True} total = Column(Integer)
__mapper_args__ = { used = Column(Integer)
'polymorphic_identity': __tablename__, 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): class Disk(Entity):
""" """
``SwapStats`` ORM model. ``Disk`` ORM model.
""" """
__tablename__ = 'swap_stats' __tablename__ = 'disk'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
total = Column(Integer)
used = Column(Integer)
free = Column(Integer)
percent = Column(Float)
__table_args__ = {'extend_existing': True} mountpoint = Column(String)
__mapper_args__ = { fstype = Column(String)
'polymorphic_identity': __tablename__, 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): class NetworkInterface(Device):
""" """
``Disk`` ORM model. ``NetworkInterface`` ORM model.
""" """
__tablename__ = 'disk' __tablename__ = 'network_interface'
id = Column( id = Column(Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
mountpoint = Column(String) bytes_sent = Column(Integer)
fstype = Column(String) bytes_recv = Column(Integer)
opts = Column(String) packets_sent = Column(Integer)
total = Column(Integer) packets_recv = Column(Integer)
used = Column(Integer) errors_in = Column(Integer)
free = Column(Integer) errors_out = Column(Integer)
percent = Column(Float) drop_in = Column(Integer)
read_count = Column(Integer) drop_out = Column(Integer)
write_count = Column(Integer) addresses = Column(JSON)
read_bytes = Column(Integer) speed = Column(Integer)
write_bytes = Column(Integer) mtu = Column(Integer)
read_time = Column(Float) duplex = Column(String)
write_time = Column(Float) flags = Column(JSON)
busy_time = Column(Float)
__table_args__ = {'extend_existing': True}
__table_args__ = {'extend_existing': True} __mapper_args__ = {
__mapper_args__ = { 'polymorphic_identity': __tablename__,
'polymorphic_identity': __tablename__, }
}
class SystemTemperature(TemperatureSensor):
if not is_defined('network_interface'): """
Extends the ``TemperatureSensor``.
class NetworkInterface(Device): """
"""
``NetworkInterface`` ORM model. __tablename__ = 'system_temperature'
"""
id = Column(
__tablename__ = 'network_interface' Integer,
ForeignKey(TemperatureSensor.id, ondelete='CASCADE'),
id = Column( primary_key=True,
Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True )
)
high = Column(Float)
bytes_sent = Column(Integer) critical = Column(Float)
bytes_recv = Column(Integer)
packets_sent = Column(Integer) __table_args__ = {'extend_existing': True}
packets_recv = Column(Integer) __mapper_args__ = {
errors_in = Column(Integer) 'polymorphic_identity': __tablename__,
errors_out = Column(Integer) }
drop_in = Column(Integer)
drop_out = Column(Integer)
addresses = Column(JSON) class SystemFan(NumericSensor):
speed = Column(Integer) """
mtu = Column(Integer) ``SystemFan`` ORM model.
duplex = Column(String) """
flags = Column(JSON)
__tablename__ = 'system_fan'
__table_args__ = {'extend_existing': True}
__mapper_args__ = { id = Column(
'polymorphic_identity': __tablename__, Integer,
} ForeignKey(NumericSensor.id, ondelete='CASCADE'),
primary_key=True,
)
if not is_defined('system_temperature'):
__table_args__ = {'extend_existing': True}
class SystemTemperature(TemperatureSensor): __mapper_args__ = {
""" 'polymorphic_identity': __tablename__,
Extends the ``TemperatureSensor``. }
"""
__tablename__ = 'system_temperature' class SystemBattery(PercentSensor):
"""
id = Column( ``SystemBattery`` ORM model.
Integer, """
ForeignKey(TemperatureSensor.id, ondelete='CASCADE'),
primary_key=True, __tablename__ = 'system_battery'
)
id = Column(
high = Column(Float) Integer,
critical = Column(Float) ForeignKey(PercentSensor.id, ondelete='CASCADE'),
primary_key=True,
__table_args__ = {'extend_existing': True} )
__mapper_args__ = {
'polymorphic_identity': __tablename__, seconds_left = Column(Float)
} power_plugged = Column(Boolean)
__table_args__ = {'extend_existing': True}
if not is_defined('system_fan'): __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__,
}
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__,
}

View file

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