Skip to content

Commit

Permalink
Fix deprecated hass.components. usage (#21)
Browse files Browse the repository at this point in the history
* Fix deprecated hass.components. usage

* lint
  • Loading branch information
ludeeus authored Jul 23, 2024
1 parent a78f5aa commit 5383a5d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ home-assistant.*
*.db*

## Integration files
templates
templates
ui-lovelace.yaml
3 changes: 2 additions & 1 deletion configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ logger:
logs:
custom_components.readme: debug

readme:
readme:
convert_lovelace: true
28 changes: 16 additions & 12 deletions custom_components/readme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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", {})
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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", [])
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions custom_components/readme/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Adds config flow for Readme."""

from collections import OrderedDict

import voluptuous as vol
Expand Down
3 changes: 2 additions & 1 deletion custom_components/readme/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for readme."""

import logging

LOGGER: logging.Logger = logging.getLogger(__package__)
Expand All @@ -18,4 +19,4 @@
If you have any issues with this you need to open an issue here:
{ISSUE_URL}
-------------------------------------------------------------------
"""
"""

0 comments on commit 5383a5d

Please sign in to comment.