From 5383a5d9125e2bd3d421dfb93f82eca49c848ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 23 Jul 2024 10:33:51 +0200 Subject: [PATCH] Fix deprecated hass.components. usage (#21) * Fix deprecated hass.components. usage * lint --- .gitignore | 3 ++- configuration.yaml | 3 ++- custom_components/readme/__init__.py | 28 ++++++++++++++----------- custom_components/readme/config_flow.py | 1 + custom_components/readme/const.py | 3 ++- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 8ce1043..fcd512d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ home-assistant.* *.db* ## Integration files -templates \ No newline at end of file +templates +ui-lovelace.yaml \ No newline at end of file diff --git a/configuration.yaml b/configuration.yaml index c1646af..3142e05 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -4,4 +4,5 @@ logger: logs: custom_components.readme: debug -readme: \ No newline at end of file +readme: + convert_lovelace: true diff --git a/custom_components/readme/__init__.py b/custom_components/readme/__init__.py index e8a7271..4cf1f19 100644 --- a/custom_components/readme/__init__.py +++ b/custom_components/readme/__init__.py @@ -4,6 +4,7 @@ For more details about this component, please refer to https://github.com/custom-components/readme """ + from __future__ import annotations import asyncio @@ -17,6 +18,7 @@ import yaml from homeassistant import config_entries from homeassistant.core import callback, HomeAssistant +from homeassistant.components.hassio import is_hassio, get_supervisor_info # type: ignore from homeassistant.helpers.template import AllStates from homeassistant.loader import Integration, IntegrationNotFound, async_get_integration from homeassistant.setup import async_get_loaded_integrations @@ -100,7 +102,7 @@ async def convert_lovelace(hass: HomeAssistant): """Convert the lovelace configuration.""" if os.path.exists(hass.config.path(".storage/lovelace")): content = ( - json.loads(await read_file(hass, ".storage/lovelace") or {}) + json.loads(await read_file(hass, ".storage/lovelace") or "{}") .get("data", {}) .get("config", {}) ) @@ -132,7 +134,9 @@ async def write_file( def write(): with open(hass.config.path(path), "w") as open_file: if as_yaml: - yaml.dump(content, open_file, default_flow_style=False, allow_unicode=True) + yaml.dump( + content, open_file, default_flow_style=False, allow_unicode=True + ) else: open_file.write(content) @@ -189,9 +193,9 @@ def get_hacs_components(hass: HomeAssistant): @callback def get_ha_installed_addons(hass: HomeAssistant) -> List[Dict[str, Any]]: - if not hass.components.hassio.is_hassio(): + if is_hassio(hass): return [] - supervisor_info = hass.components.hassio.get_supervisor_info() + supervisor_info = get_supervisor_info(hass) if supervisor_info: return supervisor_info.get("addons", []) @@ -218,14 +222,14 @@ def get_repository_name(repository) -> str: async def get_custom_integrations(hass: HomeAssistant): """Return a list with custom integration info.""" custom_integrations = [] - configured_integrations: List[ - Integration | IntegrationNotFound | BaseException - ] = await asyncio.gather( - *[ - async_get_integration(hass, domain) - for domain in async_get_loaded_integrations(hass) - ], - return_exceptions=True, + configured_integrations: List[Integration | IntegrationNotFound | BaseException] = ( + await asyncio.gather( + *[ + async_get_integration(hass, domain) + for domain in async_get_loaded_integrations(hass) + ], + return_exceptions=True, + ) ) for integration in configured_integrations: diff --git a/custom_components/readme/config_flow.py b/custom_components/readme/config_flow.py index caf4f49..613c200 100644 --- a/custom_components/readme/config_flow.py +++ b/custom_components/readme/config_flow.py @@ -1,4 +1,5 @@ """Adds config flow for Readme.""" + from collections import OrderedDict import voluptuous as vol diff --git a/custom_components/readme/const.py b/custom_components/readme/const.py index 1b86119..ea8809d 100644 --- a/custom_components/readme/const.py +++ b/custom_components/readme/const.py @@ -1,4 +1,5 @@ """Constants for readme.""" + import logging LOGGER: logging.Logger = logging.getLogger(__package__) @@ -18,4 +19,4 @@ If you have any issues with this you need to open an issue here: {ISSUE_URL} ------------------------------------------------------------------- -""" \ No newline at end of file +"""