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

Commit 3806d5c

Browse files
committed
Remove deprecated acculumative energy sensor
1 parent 81e9b96 commit 3806d5c

File tree

8 files changed

+7
-121
lines changed

8 files changed

+7
-121
lines changed

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ This integration exposes the following entities:
5757
* Sensors (Other)
5858
* CT Reading (Amps) - Reading from attached CT clamp
5959
* Energy Usage (kWh) - Energy used in the current/last session. *This is supported by the energy dashboard.*
60-
* Accumulative Energy Usage (kWh) - Deprecated - Total energy used by the charger (If enabled in options)
6160
* 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
6261
* Switches (Settings) - **Only options available to your charger model will show**
6362
* Lock Buttons - Locks buttons on charger
@@ -82,7 +81,6 @@ This integration exposes the following entities:
8281
Some options can be set from the 'Configure' menu in Home Assistant:
8382
* 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.
8483
* Don't collapse charge slots - By default, adjacent slots are merged into one. This option shows every slot, as shown in the Ohme app.
85-
* Enable accumulative energy usage sensor - Enable the sensor showing an all-time incrementing energy usage counter. This causes issues with some accounts.
8684

8785

8886
## Coordinators
@@ -102,7 +100,5 @@ The coordinators are listed with their refresh intervals below. Relevant coordin
102100
* OhmeAdvancedSettingsCoordinator (1m refresh)
103101
* Sensors: CT reading sensor
104102
* Binary Sensors: Charger online
105-
* OhmeStatisticsCoordinator (30m refresh)
106-
* Sensors: Accumulative energy usage
107103
* OhmeChargeSchedulesCoordinator (10m refresh)
108104
* Inputs: Target time, target percentage and preconditioning (If car disconnected)

custom_components/ohme/__init__.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .const import *
44
from .utils import get_option
55
from .api_client import OhmeApiClient
6-
from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator
6+
from .coordinator import OhmeChargeSessionsCoordinator, OhmeAccountInfoCoordinator, OhmeAdvancedSettingsCoordinator, OhmeChargeSchedulesCoordinator
77
from homeassistant.exceptions import ConfigEntryNotReady
88

99
_LOGGER = logging.getLogger(__name__)
@@ -40,35 +40,16 @@ async def async_setup_entry(hass, entry):
4040
coordinators = [
4141
OhmeChargeSessionsCoordinator(hass=hass), # COORDINATOR_CHARGESESSIONS
4242
OhmeAccountInfoCoordinator(hass=hass), # COORDINATOR_ACCOUNTINFO
43-
OhmeStatisticsCoordinator(hass=hass), # COORDINATOR_STATISTICS
4443
OhmeAdvancedSettingsCoordinator(hass=hass), # COORDINATOR_ADVANCED
4544
OhmeChargeSchedulesCoordinator(hass=hass) # COORDINATOR_SCHEDULES
4645
]
4746

4847
# We can function without these so setup can continue
4948
coordinators_optional = [
50-
OhmeStatisticsCoordinator,
5149
OhmeAdvancedSettingsCoordinator
5250
]
5351

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-
6052
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-
7253
# Catch failures if this is an 'optional' coordinator
7354
try:
7455
await coordinator.async_config_entry_first_refresh()

custom_components/ohme/api_client.py

-15
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ async def async_refresh_session(self):
9595

9696
# Internal methods
9797

98-
def _last_second_of_month_timestamp(self):
99-
"""Get the last second of this month."""
100-
dt = datetime.today()
101-
dt = dt.replace(day=1) + timedelta(days=32)
102-
dt = dt.replace(day=1, hour=0, minute=0, second=0,
103-
microsecond=0) - timedelta(seconds=1)
104-
return int(dt.timestamp()*1e3)
105-
10698
async def _handle_api_error(self, url, resp):
10799
"""Raise an exception if API response failed."""
108100
if resp.status != 200:
@@ -335,13 +327,6 @@ async def async_update_device_info(self, is_retry=False):
335327

336328
return True
337329

338-
async def async_get_charge_statistics(self):
339-
"""Get charge statistics. Currently this is just for all time (well, Jan 2019)."""
340-
end_ts = self._last_second_of_month_timestamp()
341-
resp = await self._get_request(f"/v1/chargeSessions/summary/users/{self._user_id}?&startTs={self._provision_date}&endTs={end_ts}&granularity=MONTH")
342-
343-
return resp['totalStats']
344-
345330
async def async_get_advanced_settings(self):
346331
"""Get advanced settings (mainly for CT clamp reading)"""
347332
resp = await self._get_request(f"/v1/chargeDevices/{self._serial}/advancedSettings")

custom_components/ohme/config_flow.py

-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ async def async_step_init(self, options):
8989
) : bool,
9090
vol.Required(
9191
"never_collapse_slots", default=self._config_entry.options.get("never_collapse_slots", False)
92-
) : bool,
93-
vol.Required(
94-
"enable_accumulative_energy", default=self._config_entry.options.get("enable_accumulative_energy", False)
9592
) : bool
9693
}), errors=errors
9794
)

custom_components/ohme/const.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
COORDINATOR_CHARGESESSIONS = 0
1414
COORDINATOR_ACCOUNTINFO = 1
15-
COORDINATOR_STATISTICS = 2
16-
COORDINATOR_ADVANCED = 3
17-
COORDINATOR_SCHEDULES = 4
15+
COORDINATOR_ADVANCED = 2
16+
COORDINATOR_SCHEDULES = 3

custom_components/ohme/coordinator.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,6 @@ async def _async_update_data(self):
5555
raise UpdateFailed("Error communicating with API")
5656

5757

58-
class OhmeStatisticsCoordinator(DataUpdateCoordinator):
59-
"""Coordinator to update statistics from API periodically.
60-
(But less so than the others)"""
61-
62-
def __init__(self, hass):
63-
"""Initialise coordinator."""
64-
super().__init__(
65-
hass,
66-
_LOGGER,
67-
name="Ohme Charger Statistics",
68-
update_interval=timedelta(minutes=30),
69-
)
70-
self._client = hass.data[DOMAIN][DATA_CLIENT]
71-
72-
async def _async_update_data(self):
73-
"""Fetch data from API endpoint."""
74-
try:
75-
return await self._client.async_get_charge_statistics()
76-
77-
except BaseException:
78-
raise UpdateFailed("Error communicating with API")
79-
8058
class OhmeAdvancedSettingsCoordinator(DataUpdateCoordinator):
8159
"""Coordinator to pull CT clamp reading."""
8260

@@ -98,6 +76,7 @@ async def _async_update_data(self):
9876
except BaseException:
9977
raise UpdateFailed("Error communicating with API")
10078

79+
10180
class OhmeChargeSchedulesCoordinator(DataUpdateCoordinator):
10281
"""Coordinator to pull charge schedules."""
10382

custom_components/ohme/sensor.py

+2-52
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from homeassistant.core import HomeAssistant, callback
1313
from homeassistant.helpers.entity import generate_entity_id
1414
from homeassistant.util.dt import (utcnow)
15-
from .const import DOMAIN, DATA_CLIENT, DATA_COORDINATORS, DATA_SLOTS, COORDINATOR_CHARGESESSIONS, COORDINATOR_STATISTICS, COORDINATOR_ADVANCED
16-
from .coordinator import OhmeChargeSessionsCoordinator, OhmeStatisticsCoordinator, OhmeAdvancedSettingsCoordinator
15+
from .const import DOMAIN, DATA_CLIENT, DATA_COORDINATORS, DATA_SLOTS, COORDINATOR_CHARGESESSIONS, COORDINATOR_ADVANCED
16+
from .coordinator import OhmeChargeSessionsCoordinator, OhmeAdvancedSettingsCoordinator
1717
from .utils import next_slot, get_option, slot_list, slot_list_str
1818

1919
_LOGGER = logging.getLogger(__name__)
@@ -28,7 +28,6 @@ async def async_setup_entry(
2828
coordinators = hass.data[DOMAIN][DATA_COORDINATORS]
2929

3030
coordinator = coordinators[COORDINATOR_CHARGESESSIONS]
31-
stats_coordinator = coordinators[COORDINATOR_STATISTICS]
3231
adv_coordinator = coordinators[COORDINATOR_ADVANCED]
3332

3433
sensors = [PowerDrawSensor(coordinator, hass, client),
@@ -41,9 +40,6 @@ async def async_setup_entry(
4140
SlotListSensor(coordinator, hass, client),
4241
BatterySOCSensor(coordinator, hass, client)]
4342

44-
if get_option(hass, "enable_accumulative_energy"):
45-
sensors.append(AccumulativeEnergyUsageSensor(stats_coordinator, hass, client))
46-
4743
async_add_entities(sensors, update_before_add=True)
4844

4945

@@ -213,52 +209,6 @@ def native_value(self):
213209
return self.coordinator.data['clampAmps']
214210

215211

216-
class AccumulativeEnergyUsageSensor(CoordinatorEntity[OhmeStatisticsCoordinator], SensorEntity):
217-
"""Sensor for total energy usage."""
218-
_attr_name = "Accumulative Energy Usage"
219-
_attr_native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
220-
_attr_suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
221-
_attr_suggested_display_precision = 1
222-
_attr_device_class = SensorDeviceClass.ENERGY
223-
_attr_state_class = SensorStateClass.TOTAL
224-
225-
def __init__(
226-
self,
227-
coordinator: OhmeStatisticsCoordinator,
228-
hass: HomeAssistant,
229-
client):
230-
super().__init__(coordinator=coordinator)
231-
232-
self._state = None
233-
self._attributes = {}
234-
self._last_updated = None
235-
self._client = client
236-
237-
self.entity_id = generate_entity_id(
238-
"sensor.{}", "ohme_accumulative_energy", hass=hass)
239-
240-
self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info(
241-
)
242-
243-
@property
244-
def unique_id(self) -> str:
245-
"""Return the unique ID of the sensor."""
246-
return self._client.get_unique_id("accumulative_energy")
247-
248-
@property
249-
def icon(self):
250-
"""Icon of the sensor."""
251-
return "mdi:lightning-bolt"
252-
253-
@property
254-
def native_value(self):
255-
"""Get value from data returned from API by coordinator"""
256-
if self.coordinator.data and self.coordinator.data['energyChargedTotalWh']:
257-
return self.coordinator.data['energyChargedTotalWh']
258-
259-
return None
260-
261-
262212
class EnergyUsageSensor(CoordinatorEntity[OhmeChargeSessionsCoordinator], SensorEntity):
263213
"""Sensor for total energy usage."""
264214
_attr_name = "Energy"

custom_components/ohme/translations/en.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"email": "Email address",
2424
"password": "Password",
2525
"never_session_specific": "Never update an ongoing session",
26-
"never_collapse_slots": "Don't collapse charge slots",
27-
"enable_accumulative_energy": "Enable accumulative energy sensor"
26+
"never_collapse_slots": "Don't collapse charge slots"
2827
},
2928
"data_description": {
3029
"password": "If you are not changing your credentials, leave the password field empty.",

0 commit comments

Comments
 (0)