Skip to content

Commit

Permalink
Add battery sensor to ohme (#134222)
Browse files Browse the repository at this point in the history
* Add battery sensor to ohme

* Forgot the snapshots!

* Add translation key to battery

* Change car to vehicle and fix snapshot tests

* Fix snapshot again - not sure what was going on with my local dev env
  • Loading branch information
dan-r authored Dec 30, 2024
1 parent 04020d5 commit a0fb6df
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
15 changes: 14 additions & 1 deletion homeassistant/components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
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

Expand Down Expand Up @@ -61,6 +66,14 @@ class OhmeSensorDescription(OhmeEntityDescription, SensorEntityDescription):
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 = [
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/ohme/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
},
"ct_current": {
"name": "CT current"
},
"vehicle_battery": {
"name": "Vehicle battery"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions tests/components/ohme/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions tests/components/ohme/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 0,
}),
}),
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
'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': <ANY>,
'entity_id': 'sensor.ohme_home_pro_vehicle_battery',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '80',
})
# ---

0 comments on commit a0fb6df

Please sign in to comment.