Skip to content

Commit

Permalink
fix: moved battery_voltage attribute to the sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
iprak committed Aug 28, 2024
1 parent 6021369 commit 78925fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 2 additions & 5 deletions custom_components/sensi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from .auth import AuthenticationConfig, refresh_access_token
from .const import (
ATTR_BATTERY_VOLTAGE,
ATTR_CIRCULATING_FAN,
ATTR_CIRCULATING_FAN_DUTY_CYCLE,
ATTR_OFFLINE,
Expand Down Expand Up @@ -124,7 +123,7 @@ class SensiDevice:
max_temp = HEAT_MAX_TEMPERATURE
cool_target: float | None = None
heat_target: float | None = None
battery_level: int | None = None
battery_voltage: float | None = None
offline: bool = True
authenticated: bool = False

Expand Down Expand Up @@ -202,9 +201,7 @@ def update(self, data_json: dict):
self.attributes[ATTR_POWER_STATUS] = state.get("power_status")
self.attributes[ATTR_WIFI_QUALITY] = state.get("wifi_connection_quality")

battery_voltage = state.get("battery_voltage")
self.attributes[ATTR_BATTERY_VOLTAGE] = battery_voltage
self.battery_level = calculate_battery_level(battery_voltage)
self.battery_voltage = state.get("battery_voltage")

self.min_temp = state.get("cool_min_temp", COOL_MIN_TEMPERATURE)
self.max_temp = state.get("heat_max_temp", HEAT_MAX_TEMPERATURE)
Expand Down
14 changes: 11 additions & 3 deletions custom_components/sensi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
from homeassistant.helpers.typing import StateType

from . import SensiDescriptionEntity
from .const import DOMAIN_DATA_COORDINATOR_KEY, SENSI_DOMAIN, Settings
from .coordinator import SensiDevice, SensiUpdateCoordinator
from .const import (
ATTR_BATTERY_VOLTAGE,
DOMAIN_DATA_COORDINATOR_KEY,
SENSI_DOMAIN,
Settings,
)
from .coordinator import SensiDevice, SensiUpdateCoordinator, calculate_battery_level


@dataclass(frozen=True)
Expand Down Expand Up @@ -56,7 +61,10 @@ class SensiSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
value_fn=lambda device: device.battery_level,
extra_state_attributes_fn=lambda device: {
ATTR_BATTERY_VOLTAGE: device.battery_voltage
},
value_fn=lambda device: calculate_battery_level(device.battery_voltage),
entity_category=EntityCategory.DIAGNOSTIC,
),
SensiSensorEntityDescription(
Expand Down

0 comments on commit 78925fe

Please sign in to comment.