From e7cfdba2bb053ddb4e002b50a0ba050743fb1ceb Mon Sep 17 00:00:00 2001 From: Jesper Date: Wed, 5 Jan 2022 07:59:15 +0100 Subject: [PATCH] Fixed the bug and made its own repository --- README.md | 9 +++------ custom_components/apsystems/manifest.json | 8 ++++---- custom_components/apsystems/sensor.py | 17 ++++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 021eeef..e7781f7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) [![apsystems](https://img.shields.io/github/v/release/bgbraga/homeassistant-apsystems.svg)](https://github.com/bgbraga/homeassistant-apsystems) ![Maintenance](https://img.shields.io/maintenance/yes/2021.svg) -##### Please contribute: -[![Buy me a beer!](https://img.shields.io/badge/Buy%20me%20a%20beer!-%F0%9F%8D%BA-yellow.svg)](https://www.buymeacoffee.com/bgbraga) - # APsystems Sensor for Home Assistant This component simplifies the integration of a APsystems inverter: * creates up to individuals sensors for easy display or use in automations @@ -19,7 +16,7 @@ It is only called from sunset to sunrise and the sensor going offline at night ### Installation Use [HACS](https://custom-components.github.io/hacs/) to point to this github URL: -https://github.com/bgbraga/homeassistant-apsystems +https://github.com/skelgaard/homeassistant-apsystems ### Configuration Use your apsystemsema.com user to configure the configuration.yaml. @@ -47,6 +44,6 @@ Get the system id inside the ```managementClickCustomer()```. 3 - sunset attribute could be on or off -[![Buy me a beer!](https://img.shields.io/badge/Buy%20me%20a%20beer!-%F0%9F%8D%BA-yellow.svg)](https://www.buymeacoffee.com/bgbraga) - +### Thanx +Thanx to the author bgbraga(https://github.com/bgbraga/) for his work, but as he has left this is in a none working stage, i have fixed the problems diff --git a/custom_components/apsystems/manifest.json b/custom_components/apsystems/manifest.json index db67009..1cf0029 100644 --- a/custom_components/apsystems/manifest.json +++ b/custom_components/apsystems/manifest.json @@ -1,9 +1,9 @@ { "domain": "apsystems", "name": "APsystems", - "documentation": "https://github.com/bgbraga/homeassistant-apsystems/blob/master/README.md", + "documentation": "https://github.com/skelgaard/homeassistant-apsystems/blob/master/README.md", "dependencies": [], - "codeowners": ["@bgbraga"], + "codeowners": ["@skelgaard"], "requirements": ["mechanize==0.4.5"], - "version": "1.0.2" -} \ No newline at end of file + "version": "1.0.4" +} diff --git a/custom_components/apsystems/sensor.py b/custom_components/apsystems/sensor.py index 61924dd..132a8e0 100644 --- a/custom_components/apsystems/sensor.py +++ b/custom_components/apsystems/sensor.py @@ -149,22 +149,21 @@ async def async_update(self): if ap_data is None: self._state = STATE_UNAVAILABLE return - index = self._metadata[0] value = ap_data[index] if isinstance(value, list): value = value[-1] - eleven_hours = 11 * 60 * 60 * 1000 # to move apsystems timestamp to UTC + offset_hours = 7 * 60 * 60 * 1000 # to move apsystems timestamp to UTC #get timestamp index_time = SENSORS[SENSOR_TIME][0] timestamp = ap_data[index_time][-1] if value == timestamp: # current attribute is the timestamp, so fix it - value = int(value) + eleven_hours + value = int(value) + offset_hours value = datetime.fromtimestamp(value / 1000) - timestamp = int(timestamp) + eleven_hours + timestamp = int(timestamp) + offset_hours self._attributes[EXTRA_TIMESTAMP] = timestamp @@ -220,6 +219,7 @@ async def run(self): try: browser = await self.login() + #TODO should this not have offset too on it ? post_data = {'queryDate': datetime.today().strftime("%Y%m%d"), 'selectedValue': self._ecu_id, 'systemId': self._system_id} @@ -233,7 +233,6 @@ async def run(self): result_data = await self._hass.async_add_executor_job( session.request, "POST", self.url_data, None, post_data, self.headers, browser.cookiejar ) - _LOGGER.debug("status code data: " + str(result_data.status_code)) if result_data.status_code == 204: @@ -253,12 +252,12 @@ async def data(self): await self.run() # continue None after run(), there is no data for this day - if self.cache is None: - return self.cache + #if self.cache is None: + # return self.cache # rules to check cache - eleven_hours = 11 * 60 * 60 * 1000 - timestamp_event = int(self.cache['time'][-1]) + eleven_hours # apsystems have 8h delayed in timestamp from UTC + offset_hours = 7 * 60 * 60 * 1000 + timestamp_event = int(self.cache['time'][-1]) + offset_hours # apsystems have 8h delayed in timestamp from UTC timestamp_now = int(round(time.time() * 1000)) cache_time = 6 * 60 * 1000 # 6 minutes request_time = 20 * 1000 # 20 seconds to avoid request what is already requested