Skip to content

Commit

Permalink
Add support for multiple dominant pollens
Browse files Browse the repository at this point in the history
  • Loading branch information
amaximus committed May 1, 2023
1 parent b988c82 commit 5bb6801
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Define sensor with the following configuration parameters:<br />
| Name | Optional | `Default` | Description |
| :---- | :---- | :------- | :----------- |
| name | **Y** | `pollen_hu` | name of the sensor |
| all_dominant | **Y** | `False` | gather all dominant pollens. By the default it will show the first dominant pollen even if there are others too. |
---

#### Example
Expand Down
2 changes: 1 addition & 1 deletion custom_components/pollen_hu/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Pollen Information Hungary",
"documentation": "https://github.com/amaximus/pollen_hu",
"issue_tracker": "https://github.com/amaximus/pollen_hu/issues",
"version": "0.0.6",
"version": "0.1.0",
"dependencies": [],
"codeowners": ["@amaximus"],
"iot_class": "cloud_polling",
Expand Down
18 changes: 15 additions & 3 deletions custom_components/pollen_hu/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@

_LOGGER = logging.getLogger(__name__)

CONF_ALLDOMINANT = 'all_dominant'
CONF_ATTRIBUTION = "Data provided by antsz.hu"
CONF_NAME = 'name'

DEFAULT_NAME = 'Pollen HU'
DEFAULT_ALLDOMINANT = False
DEFAULT_ICON = 'mdi:blur'
DEFAULT_NAME = 'Pollen HU'

SCAN_INTERVAL = timedelta(hours=1)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_ALLDOMINANT, default=DEFAULT_ALLDOMINANT): cv.boolean,
})

@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
name = config.get(CONF_NAME)
alldominant = config.get(CONF_ALLDOMINANT)

async_add_devices(
[PollenHUSensor(hass, name )],update_before_add=True)
[PollenHUSensor(hass, name, alldominant )],update_before_add=True)

async def async_get_pdata(self):
pjson = {}
Expand Down Expand Up @@ -62,10 +66,11 @@ async def async_get_pdata(self):

class PollenHUSensor(Entity):

def __init__(self, hass, name):
def __init__(self, hass, name, alldominant):
"""Initialize the sensor."""
self._hass = hass
self._name = name
self._alldominant = alldominant
self._state = None
self._pdata = []
self._icon = DEFAULT_ICON
Expand All @@ -85,6 +90,13 @@ def extra_state_attributes(self):
attr["dominant_pollen_value"] = int(val)
attr["dominant_pollen"] = item.get('name')
dominant_value = int(val)
elif int(val) == dominant_value and self._alldominant:
if 'dominant_pollen' in attr:
attr["dominant_pollen"] = attr["dominant_pollen"] + "|" + item.get('name')
else:
attr["dominant_pollen"] = item.get('name')
attr["dominant_pollen_value"] = int(val)
dominant_value = int(val)

attr["provider"] = CONF_ATTRIBUTION
return attr
Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Define sensor with the following configuration parameters:<br />
| Name | Optional | `Default` | Description |
| :---- | :---- | :------- | :----------- |
| name | **Y** | `pollen_hu` | name of the sensor |
| all_dominant | **Y** | `False` | gather all dominant pollens. By the default it will show the first dominant pollen even if there are others too. |
---

#### Example
Expand Down
6 changes: 3 additions & 3 deletions tracker.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"pollen_hu": {
"version": "0.0.6",
"updated_at": "2021-12-19",
"version": "0.1.0",
"updated_at": "2023-05-01",
"visit_repo": "https://github.com/amaximus/pollen_hu",
"changelog": "https://github.com/amaximus/pollen_hu/releases/0.0.5"
"changelog": "https://github.com/amaximus/pollen_hu/releases/0.1.0"
}
}

0 comments on commit 5bb6801

Please sign in to comment.