[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,15 +1,11 @@
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): class Cpu(Entity):
""" """
``CPU`` ORM (container) model. ``CPU`` ORM (container) model.
@ -17,9 +13,7 @@ if not is_defined('cpu'):
__tablename__ = 'cpu' __tablename__ = 'cpu'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
percent = Column(Float) percent = Column(Float)
@ -29,8 +23,6 @@ if not is_defined('cpu'):
} }
if not is_defined('cpu_info'):
class CpuInfo(Entity): class CpuInfo(Entity):
""" """
``CpuInfo`` ORM model. ``CpuInfo`` ORM model.
@ -38,9 +30,7 @@ if not is_defined('cpu_info'):
__tablename__ = 'cpu_info' __tablename__ = 'cpu_info'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
architecture = Column(String) architecture = Column(String)
bits = Column(Integer) bits = Column(Integer)
@ -61,8 +51,6 @@ if not is_defined('cpu_info'):
} }
if not is_defined('cpu_times'):
class CpuTimes(Entity): class CpuTimes(Entity):
""" """
``CpuTimes`` ORM (container) model. ``CpuTimes`` ORM (container) model.
@ -70,9 +58,7 @@ if not is_defined('cpu_times'):
__tablename__ = 'cpu_times' __tablename__ = 'cpu_times'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__table_args__ = {'extend_existing': True} __table_args__ = {'extend_existing': True}
__mapper_args__ = { __mapper_args__ = {
@ -80,8 +66,6 @@ if not is_defined('cpu_times'):
} }
if not is_defined('cpu_stats'):
class CpuStats(Entity): class CpuStats(Entity):
""" """
``CpuStats`` ORM (container) model. ``CpuStats`` ORM (container) model.
@ -89,9 +73,7 @@ if not is_defined('cpu_stats'):
__tablename__ = 'cpu_stats' __tablename__ = 'cpu_stats'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
__table_args__ = {'extend_existing': True} __table_args__ = {'extend_existing': True}
__mapper_args__ = { __mapper_args__ = {
@ -99,8 +81,6 @@ if not is_defined('cpu_stats'):
} }
if not is_defined('memory_stats'):
class MemoryStats(Entity): class MemoryStats(Entity):
""" """
``MemoryStats`` ORM model. ``MemoryStats`` ORM model.
@ -108,9 +88,7 @@ if not is_defined('memory_stats'):
__tablename__ = 'memory_stats' __tablename__ = 'memory_stats'
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) total = Column(Integer)
available = Column(Integer) available = Column(Integer)
@ -129,8 +107,6 @@ if not is_defined('memory_stats'):
} }
if not is_defined('swap_stats'):
class SwapStats(Entity): class SwapStats(Entity):
""" """
``SwapStats`` ORM model. ``SwapStats`` ORM model.
@ -138,9 +114,7 @@ if not is_defined('swap_stats'):
__tablename__ = 'swap_stats' __tablename__ = 'swap_stats'
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) total = Column(Integer)
used = Column(Integer) used = Column(Integer)
@ -153,8 +127,6 @@ if not is_defined('swap_stats'):
} }
if not is_defined('disk'):
class Disk(Entity): class Disk(Entity):
""" """
``Disk`` ORM model. ``Disk`` ORM model.
@ -162,9 +134,7 @@ if not is_defined('disk'):
__tablename__ = 'disk' __tablename__ = 'disk'
id = Column( id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
mountpoint = Column(String) mountpoint = Column(String)
fstype = Column(String) fstype = Column(String)
@ -187,8 +157,6 @@ if not is_defined('disk'):
} }
if not is_defined('network_interface'):
class NetworkInterface(Device): class NetworkInterface(Device):
""" """
``NetworkInterface`` ORM model. ``NetworkInterface`` ORM model.
@ -196,9 +164,7 @@ if not is_defined('network_interface'):
__tablename__ = 'network_interface' __tablename__ = 'network_interface'
id = Column( id = Column(Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True)
Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True
)
bytes_sent = Column(Integer) bytes_sent = Column(Integer)
bytes_recv = Column(Integer) bytes_recv = Column(Integer)
@ -220,8 +186,6 @@ if not is_defined('network_interface'):
} }
if not is_defined('system_temperature'):
class SystemTemperature(TemperatureSensor): class SystemTemperature(TemperatureSensor):
""" """
Extends the ``TemperatureSensor``. Extends the ``TemperatureSensor``.
@ -244,8 +208,6 @@ if not is_defined('system_temperature'):
} }
if not is_defined('system_fan'):
class SystemFan(NumericSensor): class SystemFan(NumericSensor):
""" """
``SystemFan`` ORM model. ``SystemFan`` ORM model.
@ -265,8 +227,6 @@ if not is_defined('system_fan'):
} }
if not is_defined('system_battery'):
class SystemBattery(PercentSensor): class SystemBattery(PercentSensor):
""" """
``SystemBattery`` ORM model. ``SystemBattery`` ORM model.

View file

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