From b4fbd3e9154057d7b56223ab3f21753a7baf8a1e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 17 Apr 2023 02:22:40 +0200 Subject: [PATCH] Added `percent` entity to `cpu`. --- platypush/plugins/system/__init__.py | 6 ++++++ platypush/schemas/system.py | 1 + 2 files changed, 7 insertions(+) diff --git a/platypush/plugins/system/__init__.py b/platypush/plugins/system/__init__.py index 076206235..09b015708 100644 --- a/platypush/plugins/system/__init__.py +++ b/platypush/plugins/system/__init__.py @@ -792,6 +792,7 @@ class SystemPlugin(SensorPlugin, EntityManager): 'cpu': { 'info': self._cpu_info, 'times': self._cpu_times_avg(), + 'percent': self.cpu_percent().output / 100.0, # type: ignore }, } ) @@ -824,6 +825,11 @@ class SystemPlugin(SensorPlugin, EntityManager): for key, time_percent in cpu['times'].items() ], ), + PercentSensor( + id='system:cpu:percent', + name='Percent', + value=cpu['percent'], + ), ], ) ] diff --git a/platypush/schemas/system.py b/platypush/schemas/system.py index 0acd0ba78..c123ca646 100644 --- a/platypush/schemas/system.py +++ b/platypush/schemas/system.py @@ -197,6 +197,7 @@ class CpuData: info: CpuInfo times: CpuTimes + percent: float = percent_field() @dataclass