mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add state of charge input number to Ohme (#169557)
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
"preconditioning_duration": {
|
||||
"default": "mdi:fan-clock"
|
||||
},
|
||||
"state_of_charge_input": {
|
||||
"default": "mdi:battery"
|
||||
},
|
||||
"target_percentage": {
|
||||
"default": "mdi:battery-heart"
|
||||
}
|
||||
|
||||
@@ -28,6 +28,18 @@ class OhmeNumberDescription(OhmeEntityDescription, NumberEntityDescription):
|
||||
|
||||
|
||||
NUMBER_DESCRIPTION = [
|
||||
OhmeNumberDescription(
|
||||
key="state_of_charge_input",
|
||||
translation_key="state_of_charge_input",
|
||||
value_fn=lambda client: client.battery,
|
||||
set_fn=lambda client, value: client.async_set_state_of_charge(int(value)),
|
||||
native_min_value=0,
|
||||
native_max_value=100,
|
||||
native_step=1,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
available_fn=lambda client: client.status.value != "unplugged",
|
||||
),
|
||||
OhmeNumberDescription(
|
||||
key="target_percentage",
|
||||
translation_key="target_percentage",
|
||||
|
||||
@@ -53,6 +53,9 @@
|
||||
"preconditioning_duration": {
|
||||
"name": "Preconditioning duration"
|
||||
},
|
||||
"state_of_charge_input": {
|
||||
"name": "State of charge input"
|
||||
},
|
||||
"target_percentage": {
|
||||
"name": "Target percentage"
|
||||
}
|
||||
|
||||
@@ -59,6 +59,66 @@
|
||||
'state': '15',
|
||||
})
|
||||
# ---
|
||||
# name: test_numbers[number.ohme_home_pro_state_of_charge_input-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'max': 100,
|
||||
'min': 0,
|
||||
'mode': <NumberMode.AUTO: 'auto'>,
|
||||
'step': 1,
|
||||
}),
|
||||
'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_state_of_charge_input',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'State of charge input',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'State of charge input',
|
||||
'platform': 'ohme',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'state_of_charge_input',
|
||||
'unique_id': 'chargerid_state_of_charge_input',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_numbers[number.ohme_home_pro_state_of_charge_input-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ohme Home Pro State of charge input',
|
||||
'max': 100,
|
||||
'min': 0,
|
||||
'mode': <NumberMode.AUTO: 'auto'>,
|
||||
'step': 1,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'number.ohme_home_pro_state_of_charge_input',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '80',
|
||||
})
|
||||
# ---
|
||||
# name: test_numbers[number.ohme_home_pro_target_percentage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
|
||||
@@ -25,14 +25,24 @@ async def test_numbers(
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Ohme sensors."""
|
||||
"""Test the Ohme numbers."""
|
||||
with patch("homeassistant.components.ohme.PLATFORMS", [Platform.NUMBER]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
entity_registry.async_update_entity(
|
||||
"number.ohme_home_pro_state_of_charge_input",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
with patch("homeassistant.components.ohme.PLATFORMS", [Platform.NUMBER]):
|
||||
await hass.config_entries.async_reload(mock_config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
async def test_set_number(
|
||||
async def test_set_target_percentage(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_client: MagicMock,
|
||||
@@ -53,3 +63,35 @@ async def test_set_number(
|
||||
)
|
||||
|
||||
assert len(mock_client.async_set_target.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_set_state_of_charge_input(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the number set."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
entity_registry.async_update_entity(
|
||||
"number.ohme_home_pro_state_of_charge_input",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_reload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
service_data={
|
||||
ATTR_VALUE: 100,
|
||||
},
|
||||
target={
|
||||
ATTR_ENTITY_ID: "number.ohme_home_pro_state_of_charge_input",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_client.async_set_state_of_charge.mock_calls) == 1
|
||||
|
||||
Reference in New Issue
Block a user