diff --git a/homeassistant/components/ohme/icons.json b/homeassistant/components/ohme/icons.json index 6982f1ef46c..a402376f990 100644 --- a/homeassistant/components/ohme/icons.json +++ b/homeassistant/components/ohme/icons.json @@ -9,6 +9,9 @@ "preconditioning_duration": { "default": "mdi:fan-clock" }, + "state_of_charge_input": { + "default": "mdi:battery" + }, "target_percentage": { "default": "mdi:battery-heart" } diff --git a/homeassistant/components/ohme/number.py b/homeassistant/components/ohme/number.py index f412c658085..fac14704aad 100644 --- a/homeassistant/components/ohme/number.py +++ b/homeassistant/components/ohme/number.py @@ -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", diff --git a/homeassistant/components/ohme/strings.json b/homeassistant/components/ohme/strings.json index c30a35d26c5..551076059ce 100644 --- a/homeassistant/components/ohme/strings.json +++ b/homeassistant/components/ohme/strings.json @@ -53,6 +53,9 @@ "preconditioning_duration": { "name": "Preconditioning duration" }, + "state_of_charge_input": { + "name": "State of charge input" + }, "target_percentage": { "name": "Target percentage" } diff --git a/tests/components/ohme/snapshots/test_number.ambr b/tests/components/ohme/snapshots/test_number.ambr index 341086dfea7..0b99c5e0b51 100644 --- a/tests/components/ohme/snapshots/test_number.ambr +++ b/tests/components/ohme/snapshots/test_number.ambr @@ -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': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + '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': , + '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': , + 'step': 1, + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'number.ohme_home_pro_state_of_charge_input', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '80', + }) +# --- # name: test_numbers[number.ohme_home_pro_target_percentage-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/ohme/test_number.py b/tests/components/ohme/test_number.py index e162cd337ae..873b0aac207 100644 --- a/tests/components/ohme/test_number.py +++ b/tests/components/ohme/test_number.py @@ -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