Skip to content

Commit 5383a5d

Browse files
authored
Fix deprecated hass.components. usage (#21)
* Fix deprecated hass.components. usage * lint
1 parent a78f5aa commit 5383a5d

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ home-assistant.*
1111
*.db*
1212

1313
## Integration files
14-
templates
14+
templates
15+
ui-lovelace.yaml

configuration.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ logger:
44
logs:
55
custom_components.readme: debug
66

7-
readme:
7+
readme:
8+
convert_lovelace: true

custom_components/readme/__init__.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
For more details about this component, please refer to
55
https://github.com/custom-components/readme
66
"""
7+
78
from __future__ import annotations
89

910
import asyncio
@@ -17,6 +18,7 @@
1718
import yaml
1819
from homeassistant import config_entries
1920
from homeassistant.core import callback, HomeAssistant
21+
from homeassistant.components.hassio import is_hassio, get_supervisor_info # type: ignore
2022
from homeassistant.helpers.template import AllStates
2123
from homeassistant.loader import Integration, IntegrationNotFound, async_get_integration
2224
from homeassistant.setup import async_get_loaded_integrations
@@ -100,7 +102,7 @@ async def convert_lovelace(hass: HomeAssistant):
100102
"""Convert the lovelace configuration."""
101103
if os.path.exists(hass.config.path(".storage/lovelace")):
102104
content = (
103-
json.loads(await read_file(hass, ".storage/lovelace") or {})
105+
json.loads(await read_file(hass, ".storage/lovelace") or "{}")
104106
.get("data", {})
105107
.get("config", {})
106108
)
@@ -132,7 +134,9 @@ async def write_file(
132134
def write():
133135
with open(hass.config.path(path), "w") as open_file:
134136
if as_yaml:
135-
yaml.dump(content, open_file, default_flow_style=False, allow_unicode=True)
137+
yaml.dump(
138+
content, open_file, default_flow_style=False, allow_unicode=True
139+
)
136140
else:
137141
open_file.write(content)
138142

@@ -189,9 +193,9 @@ def get_hacs_components(hass: HomeAssistant):
189193

190194
@callback
191195
def get_ha_installed_addons(hass: HomeAssistant) -> List[Dict[str, Any]]:
192-
if not hass.components.hassio.is_hassio():
196+
if is_hassio(hass):
193197
return []
194-
supervisor_info = hass.components.hassio.get_supervisor_info()
198+
supervisor_info = get_supervisor_info(hass)
195199

196200
if supervisor_info:
197201
return supervisor_info.get("addons", [])
@@ -218,14 +222,14 @@ def get_repository_name(repository) -> str:
218222
async def get_custom_integrations(hass: HomeAssistant):
219223
"""Return a list with custom integration info."""
220224
custom_integrations = []
221-
configured_integrations: List[
222-
Integration | IntegrationNotFound | BaseException
223-
] = await asyncio.gather(
224-
*[
225-
async_get_integration(hass, domain)
226-
for domain in async_get_loaded_integrations(hass)
227-
],
228-
return_exceptions=True,
225+
configured_integrations: List[Integration | IntegrationNotFound | BaseException] = (
226+
await asyncio.gather(
227+
*[
228+
async_get_integration(hass, domain)
229+
for domain in async_get_loaded_integrations(hass)
230+
],
231+
return_exceptions=True,
232+
)
229233
)
230234

231235
for integration in configured_integrations:

custom_components/readme/config_flow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Adds config flow for Readme."""
2+
23
from collections import OrderedDict
34

45
import voluptuous as vol

custom_components/readme/const.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants for readme."""
2+
23
import logging
34

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

0 commit comments

Comments
 (0)