Skip to content

Commit

Permalink
Removed async parts and updated the manifest after comments or @awarecan
Browse files Browse the repository at this point in the history
 [HA issue](home-assistant/core#23652 (comment)), Bumped version to 1.4.2
  • Loading branch information
Paul-dH committed May 18, 2019
1 parent 3edac29 commit 91bcacd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions custom_components.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sensor.ovapi": {
"updated_at": "2019-01-16",
"version": "1.4.1",
"updated_at": "2019-05-18",
"version": "1.4.2",
"local_location": "/custom_components/ovapi/sensor.py",
"remote_location": "https://raw.githubusercontent.com/Paul-dH/Home-Assisant-Sensor-OvApi/master/ovapi.py",
"visit_repo": "https://github.com/Paul-dH/Home-Assisant-Sensor-OvApi",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ovapi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"domain": "https://github.com/Paul-dH/Home-Assisant-Sensor-OvApi",
"domain": "ovapi",
"name": "Sensor OvApi",
"documentation": "https://github.com/Paul-dH/Home-Assisant-Sensor-OvApi",
"dependencies": [],
Expand Down
20 changes: 9 additions & 11 deletions custom_components/ovapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import homeassistant.helpers.config_validation as cv

__version__ = '1.4.1'
__version__ = '1.4.2'

_LOGGER = logging.getLogger(__name__)
_RESOURCE = 'v0.ovapi.nl'
Expand Down Expand Up @@ -63,7 +63,7 @@
})


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
def setup_platform(hass, config, add_entities, discovery_info=None):

name = config.get(CONF_NAME)
stop_code = config.get(CONF_STOP_CODE)
Expand All @@ -72,11 +72,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
future_departures = config.get(CONF_SHOW_FUTURE_DEPARTURES)
line_filter = config.get(CONF_LINE_FILTER)

async_get_clientsession(hass)

ov_api = OvApiData(stop_code, timing_point_code)

await ov_api.async_update()
ov_api.update()

if ov_api is None:
raise PlatformNotReady
Expand All @@ -90,7 +88,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
sensors.append(OvApiSensor(ov_api, (name + "_future_" + str(counter)), stop_code, timing_point_code,
route_code, line_filter, counter))

async_add_entities(sensors, True)
add_entities(sensors, True)


class OvApiSensor(Entity):
Expand Down Expand Up @@ -202,9 +200,9 @@ def device_state_attributes(self):
ATTR_UPDATE_CYCLE: str(MIN_TIME_BETWEEN_UPDATES.seconds) + ' seconds',
ATTR_CREDITS: CONF_CREDITS
}
async def async_update(self):
def update(self):
"""Get the latest data from the OvApi."""
await self._json_data.async_update()
self._json_data.update()

data = json.loads(self._json_data.result)

Expand Down Expand Up @@ -307,13 +305,13 @@ def __init__(self, stop_code, timing_point_code):
}

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self):
def update(self):
if self._stop_code == CONF_STOP_CODE and self._timing_point_code == CONF_TIMING_POINT_CODE:
_LOGGER.error("Impossible to get data from OvApi, no stop code and no timing point code.")
self.result = "Impossible to get data from OvApi, no stop code and no timing point code."
elif self._stop_code != CONF_STOP_CODE:
try:
response = http.client.HTTPConnection(self._resource)
response = http.client.HTTPConnection(self._resource, timeout=1)
response.request("GET", "/stopareacode/" + self._stop_code, headers = self._headers)
result = response.getresponse()
self.result = result.read().decode('utf-8')
Expand All @@ -322,7 +320,7 @@ async def async_update(self):
self.result = "Impossible to get data from OvApi using stop code."
else:
try:
response = http.client.HTTPConnection(self._resource)
response = http.client.HTTPConnection(self._resource, timeout=1)
response.request("GET", "/tpc/" + self._timing_point_code, headers = self._headers)
result = response.getresponse()
self.result = result.read().decode('utf-8')
Expand Down

0 comments on commit 91bcacd

Please sign in to comment.