Skip to content

Commit

Permalink
Merge pull request #83 from h4de5/feature/fix-deprecation-warnings-2024
Browse files Browse the repository at this point in the history
Fix deprecation issues for HA 2024.9.0 and 2024.10.0
  • Loading branch information
h4de5 authored Oct 19, 2024
2 parents eeb7374 + 8764a8f commit d6726c2
Show file tree
Hide file tree
Showing 14 changed files with 513 additions and 298 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ logos/Thumbs.db
*.bac
examples/rootCA.VIMAR.crt
examples/credentials.cfg
.vs
.vs
.venv
67 changes: 39 additions & 28 deletions custom_components/vimar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
"""Vimar Platform integration."""

import asyncio
import logging
import os
from datetime import timedelta
from platform import platform
from typing import Tuple
# from datetime import timedelta
# import logging
# import os
# from platform import platform
# from typing import Tuple

import async_timeout
from homeassistant.util import slugify
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.core import callback
# import async_timeout
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_TIMEOUT,
CONF_USERNAME,
CONF_VERIFY_SSL,
SERVICE_RELOAD
# CONF_VERIFY_SSL,
SERVICE_RELOAD,
)
from homeassistant.exceptions import PlatformNotReady, ConfigEntryNotReady
# from homeassistant.core import callback
from homeassistant.core import Config, HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.service import async_register_admin_service
from homeassistant.util import slugify
import voluptuous as vol

from .const import *
from .const import _LOGGER
Expand Down Expand Up @@ -61,6 +60,7 @@
SERVICE_RELOAD_DEFAULT = "reload_default"
SERVICE_RELOAD_DEFAULT_SCHEMA = vol.Schema({})


# @ asyncio.coroutine
async def async_setup(hass: HomeAssistant, config: Config):
"""Set up from config."""
Expand All @@ -86,14 +86,20 @@ async def async_setup(hass: HomeAssistant, config: Config):
if len(configured) == 0:
# get the configuration.yaml settings and make a 'flow' task :)
# this will run 'async_step_import' in config_flow.py
log.info("Importing configuration from yaml...after you can remove from yaml")
log.info(
"Importing configuration from yaml...after you can remove from yaml"
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf.copy()
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=conf.copy(),
)
)
else:
log.debug("Configuration from yaml already imported: you can remove from yaml")
log.debug(
"Configuration from yaml already imported: you can remove from yaml"
)

return True

Expand Down Expand Up @@ -138,10 +144,11 @@ async def setup_then_listen() -> None:

async def add_services(hass: HomeAssistant):
"""Add services."""

async def service_update_call(call):
forced = call.data.get("forced")
for item in hass.data[DOMAIN].values():
coordinator : VimarDataUpdateCoordinator = item
coordinator: VimarDataUpdateCoordinator = item
await coordinator.validate_vimar_credentials()
await hass.async_add_executor_job(coordinator.vimarproject.update, forced)

Expand All @@ -153,11 +160,15 @@ async def service_exec_vimar_sql_call(call):
data = call.data
sql = data.get("sql")
for item in hass.data[DOMAIN].values():
coordinator : VimarDataUpdateCoordinator = item
coordinator: VimarDataUpdateCoordinator = item
await coordinator.validate_vimar_credentials()
payload = await hass.async_add_executor_job(coordinator.vimarconnection._request_vimar_sql, sql)
payload = await hass.async_add_executor_job(
coordinator.vimarconnection._request_vimar_sql, sql
)
_LOGGER.info(
SERVICE_EXEC_VIMAR_SQL + " done: SQL: %s . Result: %s", sql, str(payload)
SERVICE_EXEC_VIMAR_SQL + " done: SQL: %s . Result: %s",
sql,
str(payload),
)

hass.services.async_register(
Expand All @@ -170,24 +181,24 @@ async def service_exec_vimar_sql_call(call):
async def _handle_reload(service):
entries_to_reload = []
for item in hass.data[DOMAIN].values():
coordinator : VimarDataUpdateCoordinator = item
coordinator: VimarDataUpdateCoordinator = item
entries_to_reload.append(coordinator.entry)
for entry in entries_to_reload:
await async_reload_entry(hass, entry)

hass.helpers.service.async_register_admin_service(
async_register_admin_service(
hass,
DOMAIN,
SERVICE_RELOAD,
_handle_reload,
)



async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Handle removal of an entry."""
if not entry.entry_id in hass.data[DOMAIN]:
return True
coordinator : VimarDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
coordinator: VimarDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
platforms = list(coordinator.devices_for_platform.keys())
unloaded = all(
await asyncio.gather(
Expand Down
Loading

0 comments on commit d6726c2

Please sign in to comment.