Add preconditioning number entity to Ohme (#138346)

* Add preconditioning number entity

* Updated test snapshots for ohme

* Update test snapshots
pull/137247/head
Dan Raper 2025-02-17 08:07:18 +00:00 committed by GitHub
parent ed3ca76696
commit 66d16336ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 77 additions and 1 deletions

View File

@ -6,6 +6,9 @@
} }
}, },
"number": { "number": {
"preconditioning_duration": {
"default": "mdi:fan-clock"
},
"target_percentage": { "target_percentage": {
"default": "mdi:battery-heart" "default": "mdi:battery-heart"
} }

View File

@ -6,7 +6,7 @@ from dataclasses import dataclass
from ohme import ApiException, OhmeApiClient from ohme import ApiException, OhmeApiClient
from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.const import PERCENTAGE from homeassistant.const import PERCENTAGE, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -37,6 +37,18 @@ NUMBER_DESCRIPTION = [
native_step=1, native_step=1,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
), ),
OhmeNumberDescription(
key="preconditioning_duration",
translation_key="preconditioning_duration",
value_fn=lambda client: client.preconditioning,
set_fn=lambda client, value: client.async_set_target(
pre_condition_length=value
),
native_min_value=0,
native_max_value=60,
native_step=5,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
] ]

View File

@ -51,6 +51,9 @@
} }
}, },
"number": { "number": {
"preconditioning_duration": {
"name": "Preconditioning duration"
},
"target_percentage": { "target_percentage": {
"name": "Target percentage" "name": "Target percentage"
} }

View File

@ -57,6 +57,7 @@ def mock_client():
client.target_soc = 50 client.target_soc = 50
client.target_time = (8, 0) client.target_time = (8, 0)
client.battery = 80 client.battery = 80
client.preconditioning = 15
client.serial = "chargerid" client.serial = "chargerid"
client.ct_connected = True client.ct_connected = True
client.energy = 1000 client.energy = 1000

View File

@ -1,4 +1,61 @@
# serializer version: 1 # serializer version: 1
# name: test_numbers[number.ohme_home_pro_preconditioning_duration-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'max': 60,
'min': 0,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 5,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'number',
'entity_category': None,
'entity_id': 'number.ohme_home_pro_preconditioning_duration',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Preconditioning duration',
'platform': 'ohme',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'preconditioning_duration',
'unique_id': 'chargerid_preconditioning_duration',
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
})
# ---
# name: test_numbers[number.ohme_home_pro_preconditioning_duration-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Ohme Home Pro Preconditioning duration',
'max': 60,
'min': 0,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 5,
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
}),
'context': <ANY>,
'entity_id': 'number.ohme_home_pro_preconditioning_duration',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '15',
})
# ---
# name: test_numbers[number.ohme_home_pro_target_percentage-entry] # name: test_numbers[number.ohme_home_pro_target_percentage-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({