Skip to content

Commit

Permalink
Merge pull request #26 from finity69x2/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
finity69x2 authored Oct 5, 2021
2 parents 48b2008 + 479084d commit 45c4a41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions custom_components/nws_alerts/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"""Configuration from yaml"""
if DOMAIN not in hass.data.keys():
hass.data.setdefault(DOMAIN, {})
config.entry_id = uuid.uuid4().hex
config.entry_id = slugify(f"{config.get(CONF_ZONE_ID)}")
config.data = config
else:
config.entry_id = uuid.uuid4().hex
config.entry_id = slugify(f"{config.get(CONF_ZONE_ID)}")
config.data = config

# Setup the data coordinator
Expand Down
1 change: 1 addition & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Constants for tests."""

CONFIG_DATA = {"name": "NWS Alerts", "zone_id": "AZZ540,AZC013"}
CONFIG_DATA_2 = {"name": "NWS Alerts YAML", "zone_id": "AZZ540"}
29 changes: 28 additions & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""Test NWS Alerts Sensors"""
from pytest_homeassistant_custom_component.common import MockConfigEntry
from homeassistant.util import slugify
from homeassistant.helpers import entity_registry as er

from custom_components.nws_alerts.const import DOMAIN
from tests.const import CONFIG_DATA
from tests.const import CONFIG_DATA, CONFIG_DATA_2

NWS_SENSOR = "sensor.nws_alerts"
NWS_SENSOR_2 = "sensor.nws_alerts_yaml"


async def test_sensor(hass):
Expand All @@ -18,3 +23,25 @@ async def test_sensor(hass):
await hass.async_block_till_done()

assert "nws_alerts" in hass.config.components
state = hass.states.get(NWS_SENSOR)
assert state
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(NWS_SENSOR)
assert entity.unique_id == f"{slugify(entry.title)}_{entry.entry_id}"

entry = MockConfigEntry(
domain=DOMAIN,
title="NWS Alerts YAML",
data=CONFIG_DATA_2,
)

entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert "nws_alerts" in hass.config.components
state = hass.states.get(NWS_SENSOR_2)
assert state
entity_registry = er.async_get(hass)
entity = entity_registry.async_get(NWS_SENSOR_2)
assert entity.unique_id == f"{slugify(entry.title)}_{entry.entry_id}"

0 comments on commit 45c4a41

Please sign in to comment.