Skip to content

Commit

Permalink
[#62] An unexpected error occured while loading the data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed Oct 8, 2024
1 parent 0958ad2 commit 3e7d75d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.9] - 2024-10-07

### Fixed
[#62](https://github.com/ssenart/home-assistant-gazpar/issues/62): An unexpected error occured while loading the data.

## [1.3.8] - 2024-10-07

### Fixed
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ sensor:
pce_identifier: 'xxxxxxxxx'
tmpdir: '/tmp'
scan_interval: '08:00:00'
lastNDays: 365
```
'name' is the sensor name (only available from version 1.3.5-alpha.1). Its default value is 'gazpar'.
'lastNDays' is the number of days of data to download from GrDF (only available from version 1.3.9). Its default value is 1095 (3 years).
If you have the error:
```
An error occurred while loading data. Status code: 500 - {"code":500,"message":"Internal Server Error"}
```
...it is likely you try to get more data than available. Please reduce the lastNDays parameter accordingly (see issue [#62](https://github.com/ssenart/home-assistant-gazpar/issues/62)).
Do not use special characters in your password.
Ensure that tmpdir already exists before starting HA. It is used to store the downloaded Excel files from GrDF.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/gazpar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requirements": [
"pygazpar==1.2.3"
],
"version": "1.3.8"
"version": "1.3.9"
}
17 changes: 12 additions & 5 deletions custom_components/gazpar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
CONF_PCE_IDENTIFIER = "pce_identifier"
CONF_WAITTIME = "wait_time"
CONF_TMPDIR = "tmpdir"
CONF_LAST_N_DAYS = "lastNDays"
CONF_DATASOURCE = "datasource"

DEFAULT_SCAN_INTERVAL = timedelta(hours=4)
DEFAULT_WAITTIME = 30
DEFAULT_LAST_N_DAYS = 1095
DEFAULT_DATASOURCE = "json"

DEFAULT_NAME = "gazpar"
Expand All @@ -47,7 +49,8 @@
vol.Optional(CONF_WAITTIME, default=DEFAULT_WAITTIME): int, # type: ignore
vol.Required(CONF_TMPDIR): cv.string,
vol.Optional(CONF_DATASOURCE, default=DEFAULT_DATASOURCE): cv.string, # type: ignore
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period # type: ignore
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period, # type: ignore
vol.Optional(CONF_LAST_N_DAYS, default=DEFAULT_LAST_N_DAYS): int # type: ignore
})


Expand Down Expand Up @@ -82,10 +85,13 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
scan_interval = config[CONF_SCAN_INTERVAL]
_LOGGER.debug(f"scan_interval={scan_interval}")

lastNDays = config[CONF_LAST_N_DAYS]
_LOGGER.debug(f"lastNDays={lastNDays}")

version = await Manifest.version()
_LOGGER.debug(f"version={version}")

account = GazparAccount(hass, name, username, password, pceIdentifier, version, wait_time, tmpdir, scan_interval, datasource)
account = GazparAccount(hass, name, username, password, pceIdentifier, wait_time, tmpdir, scan_interval, lastNDays, version, datasource)
add_entities(account.sensors, True)

if hass is not None:
Expand All @@ -105,16 +111,17 @@ class GazparAccount:
"""Representation of a Gazpar account."""

# ----------------------------------
def __init__(self, hass, name: str, username: str, password: str, pceIdentifier: str, version: str, wait_time: int, tmpdir: str, scan_interval: timedelta, datasource: str):
def __init__(self, hass, name: str, username: str, password: str, pceIdentifier: str, wait_time: int, tmpdir: str, scan_interval: timedelta, lastNDays: int, version: str, datasource: str):
"""Initialise the Gazpar account."""
self._name = name
self._username = username
self._password = password
self._pceIdentifier = pceIdentifier
self._version = version
self._wait_time = wait_time
self._tmpdir = tmpdir
self._scan_interval = scan_interval
self._lastNDays = lastNDays
self._version = version
self._datasource = datasource
self._dataByFrequency = {}
self.sensors = []
Expand Down Expand Up @@ -143,7 +150,7 @@ async def async_update_gazpar_data(self, event_time):
raise Exception(f"Invalid datasource value: '{self._datasource}' (valid values are: json | excel | test)")

loop = asyncio.get_event_loop()
self._dataByFrequency = await loop.run_in_executor(None, client.loadSince, self._pceIdentifier, 1095)
self._dataByFrequency = await loop.run_in_executor(None, client.loadSince, self._pceIdentifier, self._lastNDays)

_LOGGER.debug(f"data={json.dumps(self._dataByFrequency, indent=2)}")

Expand Down

0 comments on commit 3e7d75d

Please sign in to comment.