-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
709 additions
and
286 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.github/* @JohNan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exclude: | ||
- master | ||
- next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name-template: 'v$RESOLVED_VERSION 🌈' | ||
tag-template: 'v$RESOLVED_VERSION' | ||
change-template: '- #$NUMBER $TITLE @$AUTHOR' | ||
sort-direction: ascending | ||
categories: | ||
- title: '🚀 Features' | ||
labels: | ||
- 'feature' | ||
- 'enhancement' | ||
|
||
- title: '🐛 Bug Fixes' | ||
labels: | ||
- 'fix' | ||
- 'bugfix' | ||
- 'bug' | ||
|
||
- title: '🧰 Maintenance' | ||
label: 'chore' | ||
|
||
version-resolver: | ||
major: | ||
labels: | ||
- 'major' | ||
minor: | ||
labels: | ||
- 'minor' | ||
patch: | ||
labels: | ||
- 'patch' | ||
default: patch | ||
template: | | ||
## Changes | ||
$CHANGES | ||
## Thank you so much for helping out to keep this integration awesome | ||
$CONTRIBUTORS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: "Cron actions 16:30 every 4 days" | ||
on: | ||
schedule: | ||
- cron: '30 16 */4 * *' | ||
|
||
jobs: | ||
validate-hassfest: | ||
name: With hassfest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Hassfest validation | ||
uses: home-assistant/actions/hassfest@master | ||
|
||
validate-hacs: | ||
name: With HACS action | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: HACS Validation | ||
uses: hacs/action@main | ||
with: | ||
category: integration | ||
comment: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Release Drafter | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
update_release_draft: | ||
name: Update release draft | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Create Release | ||
uses: release-drafter/release-drafter@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
release_zip_file: | ||
name: Prepare release asset | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get version | ||
id: version | ||
uses: home-assistant/actions/helpers/version@master | ||
|
||
- name: "Set version number" | ||
run: | | ||
python3 ${{ github.workspace }}/manage/update_manifest.py --version ${{ steps.version.outputs.version }} | ||
- name: Create zip | ||
run: | | ||
cd custom_components/pollenprognos | ||
zip pollenprognos.zip -r ./ | ||
- name: Upload zip to release | ||
uses: svenstaro/upload-release-action@v1-release | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: ./custom_components/pollenprognos/pollenprognos.zip | ||
asset_name: pollenprognos.zip | ||
tag: ${{ github.ref }} | ||
overwrite: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: "Validate" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
validate-hassfest: | ||
name: With hassfest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Hassfest validation | ||
uses: home-assistant/actions/hassfest@master | ||
|
||
validate-hacs: | ||
name: With HACS action | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: HACS Validation | ||
uses: hacs/action@main | ||
with: | ||
category: integration | ||
comment: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: "Validate" | ||
|
||
on: | ||
pull_request_target: | ||
types: [opened, labeled, unlabeled, synchronize] | ||
|
||
jobs: | ||
validate-labels: | ||
name: With PR label action | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: PR Label Validation | ||
uses: jesusvasquez333/[email protected] | ||
with: | ||
github-token: '${{ secrets.GITHUB_TOKEN }}' | ||
valid-labels: 'bug, enhancement' | ||
invalid-labels: 'help wanted, invalid, question' | ||
pull-request-number: '${{ github.event.pull_request.number }}' | ||
disable-reviews: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,20 @@ | ||
# Home Assistant Pollennivå | ||
# Home Assistant Pollenprognos | ||
|
||
Support for getting current pollen levels from Pollenkollen.se | ||
Visit https://pollenkoll.se/pollenprognos/ to find available cities | ||
Visit https://pollenkoll.se/pollenprognos-ostersund/ to find available allergens | ||
|
||
Available states: | ||
### Install with HACS (recommended) | ||
Add the url to the repository as a custom integration. | ||
|
||
``` | ||
STATES = { | ||
"i.h.": 0, | ||
"L": 1, | ||
"L-M": 2, | ||
"M": 3, | ||
"M-H": 4, | ||
"H": 5, | ||
"H-H+": 6 | ||
} | ||
``` | ||
|
||
Place the folder `pollenniva` in `<HA_CONFIG_DIR>/custom_components` | ||
Add configuration to your `configuration.yaml` | ||
|
||
This will create sensors named `senson.pollenniva_CITY_ALLERGEN_day_[0-3]` and the state will be the current level of that allergen. | ||
|
||
Example configuration | ||
|
||
``` | ||
sensor: | ||
- platform: pollenniva | ||
scan_interval: 14400 # (default=14400 seconds (4 hours), optional) | ||
state_as_string: false # (default=false, optional, show states as strings as per STATES below) | ||
sensors: | ||
- city: Stockholm | ||
days_to_track: 4 # (default=4, values 1-4, optional) | ||
allergens: | ||
- Gräs | ||
- Hassel | ||
- city: Östersund | ||
allergens: | ||
- Hassel | ||
``` | ||
### Configure | ||
This integration can be configured via the Home Assistant frontend. | ||
|
||
- Go to **Configuration** -> **Integrations**. | ||
- Click on the `+` in the bottom right corner to add a new integration. | ||
- Search and select the **Pollenprognos** integration form the list. | ||
- Follow the instruction on screen to add the sensors. | ||
|
||
### Custom card for Lovelace | ||
Custom card for Lovelace can be found here: | ||
https://github.com/isabellaalstrom/pollenkoll-card | ||
|
||
<img src="https://github.com/isabellaalstrom/pollenkoll-card/blob/master/pollenkoll-card.png" alt="Pollenkoll Lovelace Card" /> | ||
|
||
### Automatic updates | ||
|
||
For update check of this sensor, add the following to your configuration.yaml. For more information, see [custom_updater](https://github.com/custom-components/custom_updater) | ||
|
||
Example configuration | ||
``` | ||
custom_updater: | ||
track: | ||
- components | ||
component_urls: | ||
- https://raw.githubusercontent.com/JohNan/home-assistant-pollenkoll/master/custom_updater.json | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Pollenprognos Custom Component.""" | ||
import asyncio | ||
import logging | ||
from datetime import timedelta, datetime | ||
|
||
from .api import PollenApi | ||
from .const import DOMAIN, PLATFORMS | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant, Config | ||
from homeassistant.exceptions import ConfigEntryNotReady | ||
from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
from homeassistant.helpers.update_coordinator import UpdateFailed, DataUpdateCoordinator | ||
|
||
SCAN_INTERVAL = timedelta(hours=4) | ||
|
||
_LOGGER: logging.Logger = logging.getLogger(__package__) | ||
|
||
|
||
async def async_setup(hass: HomeAssistant, config: Config): | ||
"""Set up this integration using YAML is not supported.""" | ||
return True | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): | ||
"""Set up this integration using UI.""" | ||
if hass.data.get(DOMAIN) is None: | ||
hass.data.setdefault(DOMAIN, {}) | ||
|
||
session = async_get_clientsession(hass) | ||
client = PollenApi(session) | ||
|
||
coordinator = PollenprognosDataUpdateCoordinator(hass, client=client) | ||
await coordinator.async_refresh() | ||
|
||
if not coordinator.last_update_success: | ||
raise ConfigEntryNotReady | ||
|
||
hass.data[DOMAIN][entry.entry_id] = coordinator | ||
|
||
for platform in PLATFORMS: | ||
if entry.options.get(platform, True): | ||
coordinator.platforms.append(platform) | ||
hass.async_add_job( | ||
hass.config_entries.async_forward_entry_setup(entry, platform) | ||
) | ||
|
||
entry.add_update_listener(async_reload_entry) | ||
return True | ||
|
||
|
||
class PollenprognosDataUpdateCoordinator(DataUpdateCoordinator): | ||
"""Class to manage fetching data from the API.""" | ||
|
||
def __init__( | ||
self, hass: HomeAssistant, client: PollenApi | ||
) -> None: | ||
"""Initialize.""" | ||
self.api = client | ||
self.platforms = [] | ||
self.last_updated = None | ||
|
||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL) | ||
|
||
async def _async_update_data(self): | ||
"""Update data via library.""" | ||
try: | ||
data = await self.api.async_get_data() | ||
self.last_updated = datetime.now() | ||
return data | ||
except Exception as exception: | ||
raise UpdateFailed() from exception | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Handle removal of an entry.""" | ||
coordinator = hass.data[DOMAIN][entry.entry_id] | ||
unloaded = all( | ||
await asyncio.gather( | ||
*[ | ||
hass.config_entries.async_forward_entry_unload(entry, platform) | ||
for platform in PLATFORMS | ||
if platform in coordinator.platforms | ||
] | ||
) | ||
) | ||
if unloaded: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unloaded | ||
|
||
|
||
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: | ||
"""Reload config entry.""" | ||
await async_unload_entry(hass, entry) | ||
await async_setup_entry(hass, entry) |
Oops, something went wrong.