diff --git a/homeassistant/components/ohme/sensor.py b/homeassistant/components/ohme/sensor.py index 6d111cf7af6..230314cba83 100644 --- a/homeassistant/components/ohme/sensor.py +++ b/homeassistant/components/ohme/sensor.py @@ -13,7 +13,12 @@ from homeassistant.components.sensor import ( SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import UnitOfElectricCurrent, UnitOfEnergy, UnitOfPower +from homeassistant.const import ( + PERCENTAGE, + UnitOfElectricCurrent, + UnitOfEnergy, + UnitOfPower, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -61,6 +66,14 @@ SENSOR_CHARGE_SESSION = [ state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda client: client.energy, ), + OhmeSensorDescription( + key="battery", + translation_key="vehicle_battery", + native_unit_of_measurement=PERCENTAGE, + device_class=SensorDeviceClass.BATTERY, + suggested_display_precision=0, + value_fn=lambda client: client.battery, + ), ] SENSOR_ADVANCED_SETTINGS = [ diff --git a/homeassistant/components/ohme/strings.json b/homeassistant/components/ohme/strings.json index a3543645d5f..98ef7306003 100644 --- a/homeassistant/components/ohme/strings.json +++ b/homeassistant/components/ohme/strings.json @@ -62,6 +62,9 @@ }, "ct_current": { "name": "CT current" + }, + "vehicle_battery": { + "name": "Vehicle battery" } } }, diff --git a/tests/components/ohme/conftest.py b/tests/components/ohme/conftest.py index e0e911e6b68..9a196a5b231 100644 --- a/tests/components/ohme/conftest.py +++ b/tests/components/ohme/conftest.py @@ -54,6 +54,7 @@ def mock_client(): client.status = ChargerStatus.CHARGING client.power = ChargerPower(0, 0, 0, 0) + client.battery = 80 client.serial = "chargerid" client.ct_connected = True client.energy = 1000 diff --git a/tests/components/ohme/snapshots/test_sensor.ambr b/tests/components/ohme/snapshots/test_sensor.ambr index fbffa5b7e5d..ea850afd151 100644 --- a/tests/components/ohme/snapshots/test_sensor.ambr +++ b/tests/components/ohme/snapshots/test_sensor.ambr @@ -266,3 +266,54 @@ 'state': 'charging', }) # --- +# name: test_sensors[sensor.ohme_home_pro_vehicle_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.ohme_home_pro_vehicle_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Vehicle battery', + 'platform': 'ohme', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'vehicle_battery', + 'unique_id': 'chargerid_battery', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.ohme_home_pro_vehicle_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'battery', + 'friendly_name': 'Ohme Home Pro Vehicle battery', + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.ohme_home_pro_vehicle_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '80', + }) +# ---