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,25 +1,19 @@
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +23,14 @@ if not is_defined('cpu'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('cpu_info'):
|
class CpuInfo(Entity):
|
||||||
|
|
||||||
class CpuInfo(Entity):
|
|
||||||
"""
|
"""
|
||||||
``CpuInfo`` ORM model.
|
``CpuInfo`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +51,14 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +66,14 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +81,14 @@ if not is_defined('cpu_stats'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('memory_stats'):
|
class MemoryStats(Entity):
|
||||||
|
|
||||||
class MemoryStats(Entity):
|
|
||||||
"""
|
"""
|
||||||
``MemoryStats`` ORM model.
|
``MemoryStats`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +107,14 @@ if not is_defined('memory_stats'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('swap_stats'):
|
class SwapStats(Entity):
|
||||||
|
|
||||||
class SwapStats(Entity):
|
|
||||||
"""
|
"""
|
||||||
``SwapStats`` ORM model.
|
``SwapStats`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +127,14 @@ if not is_defined('swap_stats'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('disk'):
|
class Disk(Entity):
|
||||||
|
|
||||||
class Disk(Entity):
|
|
||||||
"""
|
"""
|
||||||
``Disk`` ORM model.
|
``Disk`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,18 +157,14 @@ if not is_defined('disk'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('network_interface'):
|
class NetworkInterface(Device):
|
||||||
|
|
||||||
class NetworkInterface(Device):
|
|
||||||
"""
|
"""
|
||||||
``NetworkInterface`` ORM model.
|
``NetworkInterface`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__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,9 +186,7 @@ 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,9 +208,7 @@ 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,9 +227,7 @@ if not is_defined('system_fan'):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not is_defined('system_battery'):
|
class SystemBattery(PercentSensor):
|
||||||
|
|
||||||
class SystemBattery(PercentSensor):
|
|
||||||
"""
|
"""
|
||||||
``SystemBattery`` ORM model.
|
``SystemBattery`` ORM model.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -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 ()
|
||||||
|
)
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue