Skip to content

Commit

Permalink
Merge pull request #40 from xirixiz/4.1.2
Browse files Browse the repository at this point in the history
update to async
  • Loading branch information
xirixiz authored Feb 8, 2020
2 parents 262bf21 + 4e37dbd commit 475aa2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions custom_components/afvalwijzer/sensor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""
@ Authors : Bram van Dartel
@ Description : Afvalwijzer Json/Scraper Sensor - It queries mijnafvalwijzer.nl or afvalstoffendienstkalender.nl.
30-01-2020 - Rebuild from scratch! Use Python library! Breaking changes!
"""

VERSION = '4.1.1'
VERSION = '4.1.2'

from Afvaldienst import Afvaldienst
from datetime import date, datetime, timedelta
Expand All @@ -18,7 +16,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle

logger = logging.getLogger(__name__)
_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'afvalwijzer'
DOMAIN = 'afvalwijzer'
Expand All @@ -31,8 +29,7 @@
CONST_SUFFIX = 'suffix'
CONST_LABEL = 'default_label'

SCAN_INTERVAL = timedelta(seconds=5)
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=3600)
PARALLEL_UPDATES = 1

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
Expand All @@ -43,7 +40,7 @@
vol.Optional(CONST_LABEL, default="Geen"): cv.string,
})

def setup_platform(hass, config, add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Setup the sensor platform."""
provider = config.get(CONST_PROVIDER)
zipcode = config.get(CONST_ZIPCODE)
Expand All @@ -64,7 +61,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sensors = []
for name in trashTypesDefault:
sensors.append(TrashSensor(hass, name, fetch_trash_data, afvaldienst, config))
add_devices(sensors)
async_add_entities(sensors)


class TrashSensor(Entity):
Expand Down Expand Up @@ -99,7 +96,7 @@ def device_state_attributes(self):
"""Return the state attributes of the sensor."""
return self._attributes

def update(self):
async def async_update(self):
"""Fetch new state data for the sensor."""
self._fetch_trash_data.update()
self._state = self._config.get(CONST_LABEL)
Expand Down Expand Up @@ -131,7 +128,6 @@ def __init__(self, config):
"""Fetch vars."""
self._config = config

@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Fetch new state data for the sensor."""
provider = self._config.get(CONST_PROVIDER)
Expand Down
2 changes: 1 addition & 1 deletion custom_updater.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sensor.afvalwijzer": {
"version": "4.1.1",
"version": "4.1.2",
"local_location": "/custom_components/afvalwijzer/__init__.py",
"remote_location": "https://raw.githubusercontent.com/xirixiz/Home-Assistant-Sensor-Afvalwijzer/master/custom_components/afvalwijzer/__init__.py",
"visit_repo": "https://github.com/xirixiz/Home-Assistant-Sensor-Afvalwijzer/",
Expand Down

0 comments on commit 475aa2b

Please sign in to comment.