From cf263dc4324f7ce75dcfb8c0ca0d77682069f0b5 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Sat, 7 Sep 2024 22:20:15 +0200 Subject: [PATCH] Remove hass.components from hassfest --- script/hassfest/dependencies.py | 31 ------------------------- tests/hassfest/test_dependencies.py | 36 ----------------------------- 2 files changed, 67 deletions(-) diff --git a/script/hassfest/dependencies.py b/script/hassfest/dependencies.py index 66796d4dd0d2b4..95201a20c15cda 100644 --- a/script/hassfest/dependencies.py +++ b/script/hassfest/dependencies.py @@ -74,37 +74,6 @@ def visit_Import(self, node: ast.Import) -> None: if name_node.name.startswith("homeassistant.components."): self._add_reference(name_node.name.split(".")[2]) - def visit_Attribute(self, node: ast.Attribute) -> None: - """Visit Attribute node.""" - # hass.components.hue.async_create() - # Name(id=hass) - # .Attribute(attr=hue) - # .Attribute(attr=async_create) - - # self.hass.components.hue.async_create() - # Name(id=self) - # .Attribute(attr=hass) or .Attribute(attr=_hass) - # .Attribute(attr=hue) - # .Attribute(attr=async_create) - if ( - isinstance(node.value, ast.Attribute) - and node.value.attr == "components" - and ( - ( - isinstance(node.value.value, ast.Name) - and node.value.value.id == "hass" - ) - or ( - isinstance(node.value.value, ast.Attribute) - and node.value.value.attr in ("hass", "_hass") - ) - ) - ): - self._add_reference(node.attr) - else: - # Have it visit other kids - self.generic_visit(node) - ALLOWED_USED_COMPONENTS = { *{platform.value for platform in Platform}, diff --git a/tests/hassfest/test_dependencies.py b/tests/hassfest/test_dependencies.py index 84e02b2d9d584d..26ed8a01ba87cf 100644 --- a/tests/hassfest/test_dependencies.py +++ b/tests/hassfest/test_dependencies.py @@ -68,33 +68,6 @@ def test_renamed_absolute(mock_collector) -> None: assert mock_collector.unfiltered_referenced == {"renamed_absolute"} -def test_hass_components_var(mock_collector) -> None: - """Test detecting a hass_components_var reference.""" - mock_collector.visit( - ast.parse( - """ -def bla(hass): - hass.components.hass_components_var.async_do_something() -""" - ) - ) - assert mock_collector.unfiltered_referenced == {"hass_components_var"} - - -def test_hass_components_class(mock_collector) -> None: - """Test detecting a hass_components_class reference.""" - mock_collector.visit( - ast.parse( - """ -class Hello: - def something(self): - self.hass.components.hass_components_class.async_yo() -""" - ) - ) - assert mock_collector.unfiltered_referenced == {"hass_components_class"} - - def test_all_imports(mock_collector) -> None: """Test all imports together.""" mock_collector.visit( @@ -108,13 +81,6 @@ def test_all_imports(mock_collector) -> None: from homeassistant.components.child_import_field import bla import homeassistant.components.renamed_absolute as hue - -def bla(hass): - hass.components.hass_components_var.async_do_something() - -class Hello: - def something(self): - self.hass.components.hass_components_class.async_yo() """ ) ) @@ -123,6 +89,4 @@ def something(self): "subimport", "child_import_field", "renamed_absolute", - "hass_components_var", - "hass_components_class", }