finity69x2 / nws_alerts

An updated version of the nws_alerts custom integration for Home Assistant
86 stars 29 forks source link

fix: read yaml config properly #18

Closed firstof9 closed 3 years ago

firstof9 commented 3 years ago

I believe this should read the yaml config properly now.

finity69x2 commented 3 years ago

I'm not sure if you meant it or not but this change is still labelled as "draft" so I can't merge it.

firstof9 commented 3 years ago

Ya I'm still working on it, rather than have you merge a bunch of junk I'll just work on it in this draft and mark it ready once I got it going. 👍

codecov-commenter commented 3 years ago

Codecov Report

Merging #18 (a45898e) into dev (7b6ec36) will decrease coverage by 3.18%. The diff coverage is 47.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #18      +/-   ##
==========================================
- Coverage   90.32%   87.13%   -3.19%     
==========================================
  Files           4        4              
  Lines         310      311       +1     
==========================================
- Hits          280      271       -9     
- Misses         30       40      +10     
Impacted Files Coverage Δ
custom_components/nws_alerts/config_flow.py 86.48% <ø> (+0.23%) :arrow_up:
custom_components/nws_alerts/sensor.py 84.28% <30.00%> (-9.16%) :arrow_down:
custom_components/nws_alerts/__init__.py 87.33% <60.00%> (-2.87%) :arrow_down:
custom_components/nws_alerts/const.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7b6ec36...a45898e. Read the comment docs.

firstof9 commented 3 years ago

Ok @finity69x2 this should be good to go now. Tested it locally and yaml config worked just like before.

finity69x2 commented 3 years ago

I merged this to dev and so far it's seems to be working OK.

Are the only extra options the "timeout" & "interval"?

So there is no confusion could you clarify for me what the extra config options mean so I can properly update the install/usage instructions?

EDIT:

It seems I spoke too soon.

it works fine in the UI (even configuring multiple integrations) but it only works in YAML if I configure only one sensor.

In yaml if I configure more than one sensor using the following code:

sensor:
  - platform: nws_alerts
    zone_id: 'INZ009,INC033'
    name: NWS Alerts yaml
    timeout: 120
    interval: 5
  - platform: nws_alerts
    zone_id: 'ARC023'
    name: NWS Alerts yaml ark
    timeout: 120
    interval: 5

...I get the following error:

2021-07-26 16:58:00 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up nws_alerts platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/nws_alerts/sensor.py", line 67, in async_setup_platform
    async_add_entities([NWSAlertSensor(hass, config)], True)
  File "/config/custom_components/nws_alerts/sensor.py", line 80, in __init__
    super().__init__(hass.data[DOMAIN][entry.entry_id][COORDINATOR])
AttributeError: 'collections.OrderedDict' object has no attribute 'entry_id'

and only one of the sensors show up and it's always the first one configured.

If I switch the order in yaml then the "ark" sensor shows up but the plain (non-ark) "yaml" sensor doesn't and I get the above error.

sensor:
  - platform: nws_alerts
    zone_id: 'ARC023'
    name: NWS Alerts yaml ark
    timeout: 120
    interval: 5
  - platform: nws_alerts
    zone_id: 'INZ009,INC033'
    name: NWS Alerts yaml
    timeout: 120
    interval: 5
firstof9 commented 3 years ago

Ah shoot, let me double check.

EDIT:

Actually I see the issue. I'll make a new PR.