Skip to content

Commit

Permalink
Revert sensor attribute to number of hours.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbkarlsson authored Jan 19, 2025
1 parent 731efe9 commit 0c80cd5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 5 additions & 5 deletions custom_components/ev_smart_charging/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, entry):
self._charging_is_planned = False
self._charging_start_time = None
self._charging_stop_time = None
self._charging_number_of_quarters = None
self._charging_number_of_hours = None

self._opportunistic = False

Expand All @@ -80,7 +80,7 @@ def extra_state_attributes(self) -> dict:
"charging_is_planned": self._charging_is_planned,
"charging_start_time": self._charging_start_time,
"charging_stop_time": self._charging_stop_time,
"charging_number_of_quarters": self._charging_number_of_quarters,
"charging_number_of_hours": self._charging_number_of_hours,
"opportunistic": self._opportunistic,
"raw_two_days": self._raw_two_days,
"charging_schedule": self._charging_schedule,
Expand Down Expand Up @@ -167,13 +167,13 @@ def charging_stop_time(self, new_value):
self.update_ha_state()

@property
def charging_number_of_quarters(self):
def charging_number_of_quarters(self) -> int:
"""Getter for charging_number_of_quarters."""
return self._charging_number_of_quarters
return int(round(self._charging_number_of_hours * 4))

@charging_number_of_quarters.setter
def charging_number_of_quarters(self, new_value):
self._charging_number_of_quarters = new_value
self._charging_number_of_hours = new_value / 4
self.update_ha_state()

@property
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ev_smart_charging/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"charging_is_planned": {"name": "Charging is planned"},
"charging_start_time": {"name": "Charging start time"},
"charging_stop_time": {"name": "Charging stop time"},
"charging_number_of_quarters": {"name": "Charging number of quarters"},
"charging_number_of_hours": {"name": "Charging number of hours"},
"opportunistic": {"name": "Opportunistic"},
"raw_two_days": {"name": "Raw two days"},
"charging_schedule": {"name": "Charging schedule"}
Expand Down
14 changes: 10 additions & 4 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ async def test_sensor(hass, bypass_validate_input_sensors):
2022, 9, 30, 5, 0, tzinfo=ZoneInfo(key="Europe/Stockholm")
)

sensor.charging_number_of_quarters = 4
assert sensor.charging_number_of_quarters == 4

extra = sensor.extra_state_attributes
assert extra["current_price"] == 12.1
assert extra["ev_soc"] == 56
Expand All @@ -116,7 +113,16 @@ async def test_sensor(hass, bypass_validate_input_sensors):
assert extra["charging_stop_time"] == datetime(
2022, 9, 30, 5, 0, tzinfo=ZoneInfo(key="Europe/Stockholm")
)
assert extra["charging_number_of_quarters"] == 4

sensor.charging_number_of_quarters = 5
extra = sensor.extra_state_attributes
assert sensor.charging_number_of_quarters == 5
assert extra["charging_number_of_hours"] == 1.25

sensor.charging_number_of_quarters = 8
extra = sensor.extra_state_attributes
assert sensor.charging_number_of_quarters == 8
assert extra["charging_number_of_hours"] == 2

# Test sensor_status
sensor_status.set_status(CHARGING_STATUS_WAITING_CHARGING)
Expand Down

0 comments on commit 0c80cd5

Please sign in to comment.