Skip to content

Commit

Permalink
track entities referenced by states.* (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummylabs committed Jun 12, 2022
1 parent d328c20 commit 4c6e0e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/watchman/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def parse(hass, folders, ignored_files, root=None):
"""Parse a yaml or json file for entities/services"""
files_parsed = 0
entity_pattern = re.compile(
r"(?:(?<=\s)|(?<=^)|(?<=\")|(?<=\'))([A-Za-z_0-9]*\s*:)?(?:\s*)?"
r"(?:(?<=\s)|(?<=^)|(?<=\")|(?<=\'))([A-Za-z_0-9]*\s*:)?(?:\s*)?(?:states.)?"
r"((air_quality|alarm_control_panel|alert|automation|binary_sensor|button|calendar|camera|"
r"climate|counter|device_tracker|fan|group|humidifier|input_boolean|input_datetime|"
r"input_number|input_select|light|lock|media_player|number|person|plant|proximity|remote|"
Expand Down
10 changes: 10 additions & 0 deletions tests/input_regex/test_regex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sensor.test1
entity_id: sensor.test2
entity_id : sensor.test3
entity_id:sensor.test4
'{{ not is_state(''sensor.test5''
'{{ not is_state("sensor.test6"
state_attr('sensor.test7'
- sensor.test8
# sensor.test9
states.sensor.test10
21 changes: 21 additions & 0 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Test setup process."""
from copy import deepcopy
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.watchman import (
async_setup_entry,
)
from custom_components.watchman.const import DOMAIN, CONF_INCLUDED_FOLDERS
from custom_components.watchman.config_flow import DEFAULT_DATA

TEST_INCLUDED_FOLDERS = ["/workspaces/thewatchman/tests/input_regex"]


async def test_regex(hass):
"""test missing entities detection"""
options = deepcopy(DEFAULT_DATA)
options[CONF_INCLUDED_FOLDERS] = TEST_INCLUDED_FOLDERS
config_entry = MockConfigEntry(
domain="watchman", data={}, options=options, entry_id="test"
)
assert await async_setup_entry(hass, config_entry)
assert len(hass.data[DOMAIN]["entities_missing"]) == 9

0 comments on commit 4c6e0e4

Please sign in to comment.