zigul/HomeAssistant-CEZdistribuce

Cez changed API url and data format

Closed this issue · 3 comments

zigul commented

Adjust script to deal with new URL and new data format.

URL:
https://www.cezdistribuce.cz/distHdo/adam/containers/stred?code=A3B4DP1

Json:
{ "data" : [ { "primaryKey" : 3072, "ID" : 3072, "VALID_FROM" : 1603666800000, "VALID_TO" : 4070905200000, "DUMP_ID" : 37, "POVEL" : "A1B6DP1", "KOD" : "P65, P64, P66, P67, P60, P67D, P65D, P64D, P66D, P63, ", "KOD_POVELU" : "181", "SAZBA" : "D45d", "INFO" : "sazba", "PLATNOST" : "Po - Pá", "DOBA" : "20", "CAS_ZAP_1" : "0:00", "CAS_VYP_1" : "7:15", "CAS_ZAP_2" : "8:15", "CAS_VYP_2" : "9:55", "CAS_ZAP_3" : "10:55", "CAS_VYP_3" : "12:30", "CAS_ZAP_4" : "13:15", "CAS_VYP_4" : "17:30", "CAS_ZAP_5" : "18:30", "CAS_VYP_5" : "23:59", "CAS_ZAP_6" : null, "CAS_VYP_6" : null, "CAS_ZAP_7" : null, "CAS_VYP_7" : null, "CAS_ZAP_8" : null, "CAS_VYP_8" : null, "CAS_ZAP_9" : null, "CAS_VYP_9" : null, "CAS_ZAP_10" : null, "CAS_VYP_10" : null, "DATE_OF_ENTRY" : 1604311875000, "DESCRIPTION" : "2020_podzim_stred" }, { "primaryKey" : 3073, "ID" : 3073, "VALID_FROM" : 1603666800000, "VALID_TO" : 4070905200000, "DUMP_ID" : 37, "POVEL" : "A1B6DP1", "KOD" : "P65, P64, P66, P67, P60, P67D, P65D, P64D, P66D, P63, ", "KOD_POVELU" : "181", "SAZBA" : "D45d", "INFO" : "sazba", "PLATNOST" : "So - Ne", "DOBA" : "20", "CAS_ZAP_1" : "0:00", "CAS_VYP_1" : "0:10", "CAS_ZAP_2" : "1:10", "CAS_VYP_2" : "8:35", "CAS_ZAP_3" : "9:30", "CAS_VYP_3" : "11:55", "CAS_ZAP_4" : "12:55", "CAS_VYP_4" : "20:10", "CAS_ZAP_5" : "21:10", "CAS_VYP_5" : "23:59", "CAS_ZAP_6" : null, "CAS_VYP_6" : null, "CAS_ZAP_7" : null, "CAS_VYP_7" : null, "CAS_ZAP_8" : null, "CAS_VYP_8" : null, "CAS_ZAP_9" : null, "CAS_VYP_9" : null, "CAS_ZAP_10" : null, "CAS_VYP_10" : null, "DATE_OF_ENTRY" : 1604311875000, "DESCRIPTION" : "2020_podzim_stred" } ], "pageSize" : 20, "pageNumber" : 1, "pageOffset" : 0, "pageBarItems" : 5, "totalNumberOfRecords" : 2, "pagingModel" : { }, "fullyInitialized" : true, "last" : true, "firstRecordNumberForPage" : 0, "lastPageNumber" : 1, "lastRecordNumber" : 2, "onePage" : true, "pageNumbersNavigation" : [ 1 ], "defaultPageNumbersAround" : [ 1 ], "first" : true }

I can't see anything now
https://www.cezdistribuce.cz/distHdo/adam/containers/vychod?code=A1B4DP1
When I try "stred" i get something.
Why?

v0.4 gives me:

homeassistant_1  | 2020-12-21 20:11:36 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up cezdistribuce platform for binary_sensor
homeassistant_1  | Traceback (most recent call last):
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 192, in _async_setup_platform
homeassistant_1  |     await asyncio.gather(*pending)
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 301, in async_add_entities
homeassistant_1  |     await asyncio.gather(*tasks)
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 474, in _async_add_entity
homeassistant_1  |     entity.async_write_ha_state()
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_write_ha_state
homeassistant_1  |     self._async_write_ha_state()
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 305, in _async_write_ha_state
homeassistant_1  |     sstate = self.state
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 158, in state
homeassistant_1  |     return STATE_ON if self.is_on else STATE_OFF
homeassistant_1  |   File "/config/custom_components/cezdistribuce/binary_sensor.py", line 60, in is_on
homeassistant_1  |     return downloader.isHdo(self.responseJson["data"])
homeassistant_1  |   File "/config/custom_components/cezdistribuce/downloader.py", line 34, in isHdo
homeassistant_1  |     days = jsonCalendar[0]
homeassistant_1  | IndexError: list index out of range

edit: disregard. This was for a code of different distributor (eon) so the result came empty.

I can't see anything now
https://www.cezdistribuce.cz/distHdo/adam/containers/vychod?code=A1B4DP1
When I try "stred" i get something.
Why?

Working now....