From 3e7d75df9427facd32a418c0c8def548ad82c5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Senart?= <> Date: Tue, 8 Oct 2024 22:12:54 +0200 Subject: [PATCH] [#62] An unexpected error occured while loading the data. --- CHANGELOG.md | 5 +++++ README.md | 9 +++++++++ custom_components/gazpar/manifest.json | 2 +- custom_components/gazpar/sensor.py | 17 ++++++++++++----- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eed623c..4764ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index af8d68f..28c87be 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/custom_components/gazpar/manifest.json b/custom_components/gazpar/manifest.json index 63d09d2..587b640 100644 --- a/custom_components/gazpar/manifest.json +++ b/custom_components/gazpar/manifest.json @@ -11,5 +11,5 @@ "requirements": [ "pygazpar==1.2.3" ], - "version": "1.3.8" + "version": "1.3.9" } diff --git a/custom_components/gazpar/sensor.py b/custom_components/gazpar/sensor.py index c77f837..6d19749 100644 --- a/custom_components/gazpar/sensor.py +++ b/custom_components/gazpar/sensor.py @@ -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" @@ -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 }) @@ -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: @@ -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 = [] @@ -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)}")