Skip to content

Commit

Permalink
feat: battery level max 2 number dot
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymins committed Dec 16, 2024
1 parent a522525 commit 95c246b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions custom_components/ups_over_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ async def _async_update_data_megatec_q1(self, reader, writer):
"load": float(values[3]),
"frequency": float(values[4]),
"battery_voltage": float(values[5]),
"battery_level": max(
0,
min(
1,
(float(values[5]) - self.low_battery_voltage)
/ (self.full_battery_voltage - self.low_battery_voltage),
),
"battery_level": int(
max(
0,
min(
1,
(float(values[5]) - self.low_battery_voltage)
/ (self.full_battery_voltage - self.low_battery_voltage),
),
)
* 10000
)
* 100,
/ 100,
"temperature": float(values[6]),
}

Expand Down

0 comments on commit 95c246b

Please sign in to comment.