mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add battery sensor to ohme (#134222)
* 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
This commit is contained in:
parent
04020d5a56
commit
a0fb6df5ba
@ -13,7 +13,12 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import UnitOfElectricCurrent, UnitOfEnergy, UnitOfPower
|
from homeassistant.const import (
|
||||||
|
PERCENTAGE,
|
||||||
|
UnitOfElectricCurrent,
|
||||||
|
UnitOfEnergy,
|
||||||
|
UnitOfPower,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -61,6 +66,14 @@ SENSOR_CHARGE_SESSION = [
|
|||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
value_fn=lambda client: client.energy,
|
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 = [
|
SENSOR_ADVANCED_SETTINGS = [
|
||||||
|
@ -62,6 +62,9 @@
|
|||||||
},
|
},
|
||||||
"ct_current": {
|
"ct_current": {
|
||||||
"name": "CT current"
|
"name": "CT current"
|
||||||
|
},
|
||||||
|
"vehicle_battery": {
|
||||||
|
"name": "Vehicle battery"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -54,6 +54,7 @@ def mock_client():
|
|||||||
client.status = ChargerStatus.CHARGING
|
client.status = ChargerStatus.CHARGING
|
||||||
client.power = ChargerPower(0, 0, 0, 0)
|
client.power = ChargerPower(0, 0, 0, 0)
|
||||||
|
|
||||||
|
client.battery = 80
|
||||||
client.serial = "chargerid"
|
client.serial = "chargerid"
|
||||||
client.ct_connected = True
|
client.ct_connected = True
|
||||||
client.energy = 1000
|
client.energy = 1000
|
||||||
|
@ -266,3 +266,54 @@
|
|||||||
'state': 'charging',
|
'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',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user