Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 8053d69

Browse files
committed
Put accumulative energy usage sensor behind an option
1 parent e218f8b commit 8053d69

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ This integration exposes the following entities:
6060
* Next Charge Slot End - The next time your car will stop charging according to the Ohme-generated charge plan
6161
* Sensors (Other)
6262
* CT Reading (Amps) - Reading from attached CT clamp
63-
* Accumulative Energy Usage (kWh) - Total energy used by the charger
6463
* Session Energy Usage (kWh) - Energy used in the current session
64+
* Accumulative Energy Usage (kWh) - Total energy used by the charger (If enabled in options)
6565
* Battery State of Charge (%) - If your car is API connected this is read from the car, if not it is how much charge Ohme thinks it has added
6666
* Switches (Settings) - **Only options available to your charger model will show**
6767
* Lock Buttons - Locks buttons on charger
@@ -84,6 +84,7 @@ This integration exposes the following entities:
8484
## Options
8585
Some options can be set from the 'Configure' menu in Home Assistant:
8686
* Never update an ongoing session - Override the default behaviour of the target time, percentage and preconditioning inputs and only ever update the schedule, not the current session. This was added as changing the current session can cause issues for customers on Intelligent Octopus Go.
87+
* Enable accumulative energy usage sensor - Enable the sensor showing an all-time incrementing energy usage counter. This causes issues with some accounts.
8788

8889

8990
## Coordinators

custom_components/ohme/__init__.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from homeassistant import core
33
from .const import *
4+
from .utils import get_option
45
from .api_client import OhmeApiClient
56
from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator
67
from homeassistant.exceptions import ConfigEntryNotReady
@@ -25,12 +26,9 @@ async def async_setup_dependencies(hass, entry):
2526

2627
async def async_update_listener(hass, entry):
2728
"""Handle options flow credentials update."""
28-
# Re-instantiate the API client
29-
await async_setup_dependencies(hass, entry)
30-
31-
# Refresh all coordinators for good measure
32-
for coordinator in hass.data[DOMAIN][DATA_COORDINATORS]:
33-
await coordinator.async_refresh()
29+
30+
# Reload this instance
31+
await hass.config_entries.async_reload(entry.entry_id)
3432

3533

3634
async def async_setup_entry(hass, entry):
@@ -53,7 +51,24 @@ async def async_setup_entry(hass, entry):
5351
OhmeAdvancedSettingsCoordinator
5452
]
5553

54+
coordinators_skipped = []
55+
56+
# Skip statistics coordinator if we don't need it
57+
if not get_option(hass, "enable_accumulative_energy"):
58+
coordinators_skipped.append(OhmeStatisticsCoordinator)
59+
5660
for coordinator in coordinators:
61+
# If we should skip this coordinator
62+
skip = False
63+
for skipped in coordinators_skipped:
64+
if isinstance(coordinator, skipped):
65+
skip = True
66+
break
67+
68+
if skip:
69+
_LOGGER.debug(f"Skipping initial load of {coordinator.__class__.__name__}")
70+
continue
71+
5772
# Catch failures if this is an 'optional' coordinator
5873
try:
5974
await coordinator.async_config_entry_first_refresh()

custom_components/ohme/config_flow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ async def async_step_init(self, options):
8686
): str,
8787
vol.Required(
8888
"never_session_specific", default=self._config_entry.options.get("never_session_specific", False)
89+
) : bool,
90+
vol.Required(
91+
"enable_accumulative_energy", default=self._config_entry.options.get("enable_accumulative_energy", False)
8992
) : bool
9093
}), errors=errors
9194
)

custom_components/ohme/sensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from homeassistant.util.dt import (utcnow)
1818
from .const import DOMAIN, DATA_CLIENT, DATA_COORDINATORS, DATA_SLOTS, COORDINATOR_CHARGESESSIONS, COORDINATOR_STATISTICS, COORDINATOR_ADVANCED
1919
from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAdvancedSettingsCoordinator
20-
from .utils import charge_graph_next_slot, charge_graph_slot_list
20+
from .utils import charge_graph_next_slot, charge_graph_slot_list, get_option
2121

2222
_LOGGER = logging.getLogger(__name__)
2323

@@ -39,11 +39,13 @@ async def async_setup_entry(
3939
VoltageSensor(coordinator, hass, client),
4040
CTSensor(adv_coordinator, hass, client),
4141
EnergyUsageSensor(coordinator, hass, client),
42-
AccumulativeEnergyUsageSensor(stats_coordinator, hass, client),
4342
NextSlotEndSensor(coordinator, hass, client),
4443
NextSlotStartSensor(coordinator, hass, client),
4544
SlotListSensor(coordinator, hass, client),
4645
BatterySOCSensor(coordinator, hass, client)]
46+
47+
if get_option(hass, "enable_accumulative_energy"):
48+
sensors.append(AccumulativeEnergyUsageSensor(stats_coordinator, hass, client))
4749

4850
async_add_entities(sensors, update_before_add=True)
4951

custom_components/ohme/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"data": {
2323
"email": "Email address",
2424
"password": "Password",
25-
"never_session_specific": "Never update an ongoing session"
25+
"never_session_specific": "Never update an ongoing session",
26+
"enable_accumulative_energy": "Enable accumulative energy sensor"
2627
},
2728
"data_description": {
2829
"password": "If you are not changing your credentials, leave the password field empty.",

custom_components/ohme/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,6 @@ def session_in_progress(hass, data):
199199
return True
200200

201201

202-
def get_option(hass, option):
203-
"""Return option value, default to False."""
204-
return hass.data[DOMAIN][DATA_OPTIONS].get(option, None)
202+
def get_option(hass, option, default=False):
203+
"""Return option value, with settable default."""
204+
return hass.data[DOMAIN][DATA_OPTIONS].get(option, default)

0 commit comments

Comments
 (0)