Skip to content

Commit

Permalink
Added scan_interval configuration option.
Browse files Browse the repository at this point in the history
Changed default update time to 1 hour.
  • Loading branch information
boralyl committed May 27, 2020
1 parent 71b5074 commit dc7976b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@ sale on your wish list in home assistant.

## Configuration

| Name | Required | Description |
| -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| country | yes | The 2 letter country code. See [Supported Countries](#supported-countries) below. |
| wishlist | yes | A list of Nintendo Switch titles. Each item can be the exact title or just the beginning of a title in order to match multiple games. For example `Shantae` would trigger when any one of the many `Shantae` games goes on sale. Read [how wishlist matching works](#how-wish-list-matching-works) below. |
| Name | Required | Description |
| ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| country | yes | The 2 letter country code. See [Supported Countries](#supported-countries) below. |
| wishlist | yes | A list of Nintendo Switch titles. Each item can be the exact title or just the beginning of a title in order to match multiple games. For example `Shantae` would trigger when any one of the many `Shantae` games goes on sale. Read [how wishlist matching works](#how-wish-list-matching-works) below. |
| scan_interval | no | The minimum time interval between updates. See [time period dictionary](#time-period-dictionary) below for an example of accepted values. _Defaults to 1 hour._ |

### Time Period Dictionary

```yaml
scan_interval:
# at least one of the following must be specified:
days: 0
hours: 0
minutes: 3
seconds: 30
milliseconds: 0
```
## Sample Configuration
Expand Down
9 changes: 7 additions & 2 deletions custom_components/nintendo_wishlist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

import homeassistant.helpers.config_validation as cv
from homeassistant import core
from homeassistant.const import CONF_SCAN_INTERVAL
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import CONF_COUNTRY, CONF_WISHLIST, DOMAIN, SCAN_INTERVAL
from .const import CONF_COUNTRY, CONF_WISHLIST, DOMAIN, DEFAULT_SCAN_INTERVAL
from .eshop import Country, EShop


Expand All @@ -20,6 +21,9 @@
{
vol.Required(CONF_WISHLIST): cv.ensure_list,
vol.Required(CONF_COUNTRY): cv.enum(Country),
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): vol.All(cv.time_period, cv.positive_timedelta),
}
)
},
Expand All @@ -39,6 +43,7 @@ async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
conf = config[DOMAIN]
country = conf[CONF_COUNTRY].name
wishlist = conf[CONF_WISHLIST]
scan_interval = conf[CONF_SCAN_INTERVAL]
eshop = EShop(country, async_get_clientsession(hass), wishlist)
coordinator = DataUpdateCoordinator(
hass,
Expand All @@ -47,7 +52,7 @@ async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
name=DOMAIN,
update_method=eshop.fetch_on_sale,
# Polling interval. Will only be polled if there are subscribers.
update_interval=SCAN_INTERVAL,
update_interval=scan_interval,
)

# Fetch initial data so we have data when entities subscribe
Expand Down
5 changes: 4 additions & 1 deletion custom_components/nintendo_wishlist/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
try:
from homeassistant.components.binary_sensor import BinarySensorEntity
except ImportError:
from homeassistant.components.binary_sensor import BinarySensorDevice as BinarySensorEntity
# Prior to HA 0.110
from homeassistant.components.binary_sensor import (
BinarySensorDevice as BinarySensorEntity,
)

from .const import DOMAIN
from .types import SwitchGame
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nintendo_wishlist/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
CONF_COUNTRY = "country"
CONF_WISHLIST = "wishlist"
DOMAIN = "nintendo_wishlist"
SCAN_INTERVAL = timedelta(minutes=10)
DEFAULT_SCAN_INTERVAL = timedelta(hours=1)

0 comments on commit dc7976b

Please sign in to comment.