Added percent entity to cpu.

This commit is contained in:
Fabio Manganiello 2023-04-17 02:22:40 +02:00
parent 711cc2b239
commit b4fbd3e915
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 7 additions and 0 deletions

View file

@ -792,6 +792,7 @@ class SystemPlugin(SensorPlugin, EntityManager):
'cpu': { 'cpu': {
'info': self._cpu_info, 'info': self._cpu_info,
'times': self._cpu_times_avg(), '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() for key, time_percent in cpu['times'].items()
], ],
), ),
PercentSensor(
id='system:cpu:percent',
name='Percent',
value=cpu['percent'],
),
], ],
) )
] ]

View file

@ -197,6 +197,7 @@ class CpuData:
info: CpuInfo info: CpuInfo
times: CpuTimes times: CpuTimes
percent: float = percent_field()
@dataclass @dataclass