Skip to content

Commit bdafd38

Browse files
committed
Change sensor battery level to percentage
1 parent 53f5dc4 commit bdafd38

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

custom_components/powersensor/PowersensorSensorEntity.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
2-
from homeassistant.const import UnitOfPower, UnitOfElectricPotential, UnitOfEnergy
2+
from homeassistant.const import UnitOfPower, UnitOfEnergy, PERCENTAGE
33
from homeassistant.core import HomeAssistant
44
from homeassistant.helpers.device_registry import DeviceInfo
55

@@ -15,11 +15,12 @@
1515
_config = {
1616
SensorMeasurements.Battery: {
1717
"name": "Battery Level",
18-
"device_class": SensorDeviceClass.VOLTAGE,
19-
"unit": UnitOfElectricPotential.VOLT,
18+
"device_class": SensorDeviceClass.BATTERY,
19+
"unit": PERCENTAGE,
2020
"precision": 2,
2121
'event': 'battery_level',
22-
'message_key': 'volts'
22+
'message_key': 'volts',
23+
'callback': lambda v: max(min(100.0*(v-3.3)/0.85,100),0) # 0% = 3.3 V , 100% = 4.15 V
2324
},
2425
SensorMeasurements.WATTS: {
2526
"name": "Power",

0 commit comments

Comments
 (0)