Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update interval 2h & graph data limited to last and current month #123

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion custom_components/nexxtmove/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ async def _async_update_data(self) -> dict | None:
raise UpdateFailed(f"NexxtmoveException {exception}") from exception
except Exception as exception:
raise UpdateFailed(f"Exception {exception}") from exception

items: list[NexxtmoveItem] = items

current_items = {
Expand Down
39 changes: 10 additions & 29 deletions custom_components/nexxtmove/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import copy
import datetime
from datetime import datetime, timedelta
import logging

from dateutil.relativedelta import relativedelta
Expand All @@ -12,7 +12,6 @@
BASE_HEADERS,
CONNECTION_RETRY,
DEFAULT_NEXXTMOVE_ENVIRONMENT,
GRAPH_START_DATE,
REQUEST_TIMEOUT,
)
from .exceptions import BadCredentialsException, NexxtmoveServiceException
Expand Down Expand Up @@ -271,15 +270,19 @@ def fetch_data(self):
state=charging_device.get("buildingName"),
extra_attributes=charging_device,
)

end_date = datetime.datetime.now().strftime("%Y%m%d")
start_date = (
(datetime.now().replace(day=1) - timedelta(days=datetime.now().day))
.replace(day=1)
.strftime("%Y%m%d")
)
end_date = datetime.now().strftime("%Y%m%d")
extra_attributes = {
"start_date": GRAPH_START_DATE,
"start_date": start_date,
"end_date": end_date,
}
graph_data = self.charging_device_graph(
charging_device_id,
GRAPH_START_DATE,
start_date,
end_date,
)

Expand Down Expand Up @@ -383,9 +386,7 @@ def fetch_data(self):
)
# Montly charge sessions
start_date = (
datetime.datetime.now()
- relativedelta(months=1)
+ relativedelta(days=1)
datetime.now() - relativedelta(months=1) + relativedelta(days=1)
).strftime("%Y%m%d")
extra_attributes = {
"start_date": start_date,
Expand Down Expand Up @@ -496,26 +497,6 @@ def fetch_data(self):
| {"dates": monthly_date, "values": monthly_charges},
)

"""
tokens = self.charging_device_tokens(charging_device_id)
_LOGGER.debug(f"Charging tokens: {tokens}", True)

#Switch will be used when it becomes useful
key = format_entity_name(
f"{self.username} charging device {charging_device_id} switch"
)
data[key] = NexxtmoveItem(
name=charging_device.get("name"),
key=key,
type="charging_device",
sensor_type="switch",
device_key=device_key,
device_name=device_name,
device_model=device_model,
state=False,
)
"""

pin = self.device_pin(charging_device.get("id"))
if pin is not False:
key = format_entity_name(
Expand Down
4 changes: 1 addition & 3 deletions custom_components/nexxtmove/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

UNRECORDED_ATTRIBUTES = {"charges", "events", "dates", "values"}

GRAPH_START_DATE = "20220101"

COORDINATOR_UPDATE_INTERVAL = timedelta(minutes=5)
COORDINATOR_UPDATE_INTERVAL = timedelta(minutes=120)
CONNECTION_RETRY = 5
REQUEST_TIMEOUT = 20
WEBSITE = "https://nexxtmove.me/"
Expand Down
Loading