Moved CPU percentage on the level of the CPU entity instead of a child entity.

This commit is contained in:
Fabio Manganiello 2023-04-19 01:48:05 +02:00
parent 4ebfbf3851
commit 153d03d43f
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
4 changed files with 50 additions and 6 deletions

View File

@ -0,0 +1,46 @@
<template>
<div class="entity cpu-container">
<div class="head">
<div class="col-1 icon">
<EntityIcon
:entity="value"
:loading="loading"
:error="error" />
</div>
<div class="col-9 label">
<div class="name" v-text="value.name" />
</div>
<div class="col-2 value" v-text="Math.round(value.percent * 100, 1) + '%'" />
</div>
</div>
</template>
<script>
import EntityMixin from "./EntityMixin"
import EntityIcon from "./EntityIcon"
export default {
name: 'Cpu',
components: {EntityIcon},
mixins: [EntityMixin],
}
</script>
<style lang="scss" scoped>
@import "common";
.cpu-container {
.head {
.value {
text-align: right;
font-weight: bold;
}
}
.icon {
margin-right: 1em;
}
}
</style>

View File

@ -135,6 +135,7 @@ export default {
.value {
text-align: right;
font-weight: bold;
}
}
}

View File

@ -18,6 +18,8 @@ if 'cpu' not in Base.metadata:
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
)
percent = Column(Float)
__mapper_args__ = {
'polymorphic_identity': __tablename__,
}

View File

@ -807,6 +807,7 @@ class SystemPlugin(SensorPlugin, EntityManager):
Cpu(
id='system:cpu',
name='CPU',
percent=cpu['percent'],
children=[
CpuInfoModel(
id='system:cpu:info',
@ -857,11 +858,6 @@ class SystemPlugin(SensorPlugin, EntityManager):
max=cpu['frequency']['max'],
unit='MHz',
),
PercentSensor(
id='system:cpu:percent',
name='Percent',
value=cpu['percent'],
),
],
),
MemoryStatsModel(