Skip to content

Commit 7249a3c

Browse files
authored
Portainer refactor sensor defaults (home-assistant#155543)
1 parent 21fce10 commit 7249a3c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

homeassistant/components/portainer/sensor.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,39 +161,34 @@ class PortainerEndpointSensorEntityDescription(SensorEntityDescription):
161161
translation_key="containers_count",
162162
value_fn=lambda data: data.docker_info.containers,
163163
entity_category=EntityCategory.DIAGNOSTIC,
164-
entity_registry_enabled_default=False,
165164
state_class=SensorStateClass.MEASUREMENT,
166165
),
167166
PortainerEndpointSensorEntityDescription(
168167
key="containers_running",
169168
translation_key="containers_running",
170169
value_fn=lambda data: data.docker_info.containers_running,
171170
entity_category=EntityCategory.DIAGNOSTIC,
172-
entity_registry_enabled_default=False,
173171
state_class=SensorStateClass.MEASUREMENT,
174172
),
175173
PortainerEndpointSensorEntityDescription(
176174
key="containers_stopped",
177175
translation_key="containers_stopped",
178176
value_fn=lambda data: data.docker_info.containers_stopped,
179177
entity_category=EntityCategory.DIAGNOSTIC,
180-
entity_registry_enabled_default=False,
181178
state_class=SensorStateClass.MEASUREMENT,
182179
),
183180
PortainerEndpointSensorEntityDescription(
184181
key="containers_paused",
185182
translation_key="containers_paused",
186183
value_fn=lambda data: data.docker_info.containers_paused,
187184
entity_category=EntityCategory.DIAGNOSTIC,
188-
entity_registry_enabled_default=False,
189185
state_class=SensorStateClass.MEASUREMENT,
190186
),
191187
PortainerEndpointSensorEntityDescription(
192188
key="images_count",
193189
translation_key="images_count",
194190
value_fn=lambda data: data.docker_info.images,
195191
entity_category=EntityCategory.DIAGNOSTIC,
196-
entity_registry_enabled_default=False,
197192
state_class=SensorStateClass.MEASUREMENT,
198193
),
199194
PortainerEndpointSensorEntityDescription(
@@ -203,6 +198,7 @@ class PortainerEndpointSensorEntityDescription(SensorEntityDescription):
203198
device_class=SensorDeviceClass.DATA_SIZE,
204199
state_class=SensorStateClass.MEASUREMENT,
205200
native_unit_of_measurement=UnitOfInformation.BYTES,
201+
suggested_unit_of_measurement=UnitOfInformation.MEBIBYTES,
206202
entity_category=EntityCategory.DIAGNOSTIC,
207203
entity_registry_enabled_default=False,
208204
),

tests/components/portainer/snapshots/test_sensor.ambr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,10 @@
11701170
'name': None,
11711171
'options': dict({
11721172
'sensor': dict({
1173-
'suggested_display_precision': 0,
1173+
'suggested_display_precision': 2,
1174+
}),
1175+
'sensor.private': dict({
1176+
'suggested_unit_of_measurement': <UnitOfInformation.MEBIBYTES: 'MiB'>,
11741177
}),
11751178
}),
11761179
'original_device_class': <SensorDeviceClass.DATA_SIZE: 'data_size'>,
@@ -1182,7 +1185,7 @@
11821185
'supported_features': 0,
11831186
'translation_key': 'memory_total',
11841187
'unique_id': 'portainer_test_entry_123_1_memory_total',
1185-
'unit_of_measurement': <UnitOfInformation.BYTES: 'B'>,
1188+
'unit_of_measurement': <UnitOfInformation.MEBIBYTES: 'MiB'>,
11861189
})
11871190
# ---
11881191
# name: test_all_entities[sensor.my_environment_total_memory-state]
@@ -1191,14 +1194,14 @@
11911194
'device_class': 'data_size',
11921195
'friendly_name': 'my-environment Total memory',
11931196
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
1194-
'unit_of_measurement': <UnitOfInformation.BYTES: 'B'>,
1197+
'unit_of_measurement': <UnitOfInformation.MEBIBYTES: 'MiB'>,
11951198
}),
11961199
'context': <ANY>,
11971200
'entity_id': 'sensor.my_environment_total_memory',
11981201
'last_changed': <ANY>,
11991202
'last_reported': <ANY>,
12001203
'last_updated': <ANY>,
1201-
'state': '2095882240',
1204+
'state': '1998.7890625',
12021205
})
12031206
# ---
12041207
# name: test_all_entities[sensor.practical_morse_cpu_usage_total-entry]

0 commit comments

Comments
 (0)