forked from platypush/platypush
[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:
parent
7cc7009d08
commit
9d086a4a10
2 changed files with 206 additions and 244 deletions
|
@ -1,15 +1,11 @@
|
|||
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.
|
||||
|
@ -17,9 +13,7 @@ if not is_defined('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)
|
||||
|
||||
|
@ -29,8 +23,6 @@ if not is_defined('cpu'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('cpu_info'):
|
||||
|
||||
class CpuInfo(Entity):
|
||||
"""
|
||||
``CpuInfo`` ORM model.
|
||||
|
@ -38,9 +30,7 @@ if not is_defined('cpu_info'):
|
|||
|
||||
__tablename__ = 'cpu_info'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
architecture = Column(String)
|
||||
bits = Column(Integer)
|
||||
|
@ -61,8 +51,6 @@ if not is_defined('cpu_info'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('cpu_times'):
|
||||
|
||||
class CpuTimes(Entity):
|
||||
"""
|
||||
``CpuTimes`` ORM (container) model.
|
||||
|
@ -70,9 +58,7 @@ if not is_defined('cpu_times'):
|
|||
|
||||
__tablename__ = 'cpu_times'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
__table_args__ = {'extend_existing': True}
|
||||
__mapper_args__ = {
|
||||
|
@ -80,8 +66,6 @@ if not is_defined('cpu_times'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('cpu_stats'):
|
||||
|
||||
class CpuStats(Entity):
|
||||
"""
|
||||
``CpuStats`` ORM (container) model.
|
||||
|
@ -89,9 +73,7 @@ if not is_defined('cpu_stats'):
|
|||
|
||||
__tablename__ = 'cpu_stats'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
__table_args__ = {'extend_existing': True}
|
||||
__mapper_args__ = {
|
||||
|
@ -99,8 +81,6 @@ if not is_defined('cpu_stats'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('memory_stats'):
|
||||
|
||||
class MemoryStats(Entity):
|
||||
"""
|
||||
``MemoryStats`` ORM model.
|
||||
|
@ -108,9 +88,7 @@ if not is_defined('memory_stats'):
|
|||
|
||||
__tablename__ = 'memory_stats'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
total = Column(Integer)
|
||||
available = Column(Integer)
|
||||
|
@ -129,8 +107,6 @@ if not is_defined('memory_stats'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('swap_stats'):
|
||||
|
||||
class SwapStats(Entity):
|
||||
"""
|
||||
``SwapStats`` ORM model.
|
||||
|
@ -138,9 +114,7 @@ if not is_defined('swap_stats'):
|
|||
|
||||
__tablename__ = 'swap_stats'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
total = Column(Integer)
|
||||
used = Column(Integer)
|
||||
|
@ -153,8 +127,6 @@ if not is_defined('swap_stats'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('disk'):
|
||||
|
||||
class Disk(Entity):
|
||||
"""
|
||||
``Disk`` ORM model.
|
||||
|
@ -162,9 +134,7 @@ if not is_defined('disk'):
|
|||
|
||||
__tablename__ = 'disk'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
mountpoint = Column(String)
|
||||
fstype = Column(String)
|
||||
|
@ -187,8 +157,6 @@ if not is_defined('disk'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('network_interface'):
|
||||
|
||||
class NetworkInterface(Device):
|
||||
"""
|
||||
``NetworkInterface`` ORM model.
|
||||
|
@ -196,9 +164,7 @@ if not is_defined('network_interface'):
|
|||
|
||||
__tablename__ = 'network_interface'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
id = Column(Integer, ForeignKey(Device.id, ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
bytes_sent = 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):
|
||||
"""
|
||||
Extends the ``TemperatureSensor``.
|
||||
|
@ -244,8 +208,6 @@ if not is_defined('system_temperature'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('system_fan'):
|
||||
|
||||
class SystemFan(NumericSensor):
|
||||
"""
|
||||
``SystemFan`` ORM model.
|
||||
|
@ -265,8 +227,6 @@ if not is_defined('system_fan'):
|
|||
}
|
||||
|
||||
|
||||
if not is_defined('system_battery'):
|
||||
|
||||
class SystemBattery(PercentSensor):
|
||||
"""
|
||||
``SystemBattery`` ORM model.
|
||||
|
|
|
@ -634,6 +634,7 @@ class SystemPlugin(SensorPlugin, EntityManager):
|
|||
if fan.get('id') and fan.get('label')
|
||||
],
|
||||
*[
|
||||
(
|
||||
SystemBattery(
|
||||
id='system:battery',
|
||||
name='Battery',
|
||||
|
@ -641,6 +642,7 @@ class SystemPlugin(SensorPlugin, EntityManager):
|
|||
)
|
||||
if battery
|
||||
else ()
|
||||
)
|
||||
],
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue