Skip to content

Commit

Permalink
Fixed the bug and made its own repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper committed Jan 5, 2022
1 parent 1b4c32f commit e7cfdba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions custom_components/apsystems/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
"version": "1.0.4"
}
17 changes: 8 additions & 9 deletions custom_components/apsystems/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit e7cfdba

Please sign in to comment.