-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ 1.0.19 ] Changed all
media_player.async_write_ha_state()
calls to…
… `schedule_update_ha_state(force_refresh=True)` calls due to HA 2024.5 release requirements. This fixes the issue of "Failed to call service X. Detected that custom integration 'Y' calls async_write_ha_state from a thread at Z. Please report it to the author of the 'Y' custom integration.". * Added more information to system health display (version, integration configs, etc). * Updated Python version from 3.11 to 3.12.3 due to HA 2024.5 release requirements.
- Loading branch information
Showing
9 changed files
with
114 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,79 @@ | ||
"""Provide info to system health.""" | ||
from typing import Any | ||
import json | ||
|
||
from homeassistant.components import system_health | ||
from homeassistant.core import HomeAssistant, callback | ||
|
||
from .const import DOMAIN | ||
from .instancedata_spotifyplus import InstanceDataSpotifyPlus | ||
|
||
# get smartinspect logger reference; create a new session for this module name. | ||
from smartinspectpython.siauto import SIAuto, SILevel, SISession | ||
import logging | ||
_logsi:SISession = SIAuto.Si.GetSession(__name__) | ||
if (_logsi == None): | ||
_logsi = SIAuto.Si.AddSession(__name__, True) | ||
_logsi.SystemLogger = logging.getLogger(__name__) | ||
|
||
|
||
@callback | ||
def async_register( | ||
hass: HomeAssistant, register: system_health.SystemHealthRegistration | ||
) -> None: | ||
def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegistration) -> None: | ||
"""Register system health callbacks.""" | ||
register.async_register_info(system_health_info) | ||
register.async_register_info(system_health_info, "/config/integrations/integration/%s" % DOMAIN) | ||
|
||
|
||
async def system_health_info(hass): | ||
"""Get info for the info page.""" | ||
return { | ||
"api_endpoint_reachable": system_health.async_check_can_reach_url( | ||
hass, "https://api.spotify.com" | ||
) | ||
} | ||
|
||
try: | ||
|
||
# trace. | ||
_logsi.EnterMethod(SILevel.Debug) | ||
|
||
# create dictionary for health information. | ||
healthInfo: dict[str, Any] = {} | ||
|
||
# add manifest file details. | ||
myConfigDir:str = "%s/custom_components/%s" % (hass.config.config_dir, DOMAIN) | ||
myManifestPath:str = "%s/manifest.json" % (myConfigDir) | ||
_logsi.LogTextFile(SILevel.Verbose, "Integration Manifest File (%s)" % myManifestPath, myManifestPath) | ||
with open(myManifestPath) as reader: | ||
data = reader.read() | ||
myManifest:dict = json.loads(data) | ||
healthInfo["integration_version"] = myManifest.get('version','unknown') | ||
|
||
# add client configuration data. | ||
clientConfig:str = "" | ||
if len(hass.data[DOMAIN]) > 0: | ||
clientConfig = str("%d: " % len(hass.data[DOMAIN])) | ||
data:InstanceDataSpotifyPlus = None | ||
for data in hass.data[DOMAIN].values(): | ||
_logsi.LogDictionary(SILevel.Verbose, "InstanceDataSpotifyPlus data", data, prettyPrint=True) | ||
if data.spotifyClient != None: | ||
if data.spotifyClient.UserProfile != None: | ||
clientConfig = clientConfig + "%s (%s), " % (data.spotifyClient.UserProfile.DisplayName, data.spotifyClient.UserProfile.Product) | ||
clientConfig = clientConfig[:len(clientConfig)-2] # drop ending ", " | ||
else: | ||
clientConfig = "(None Defined)" | ||
healthInfo["clients_configured"] = clientConfig | ||
|
||
# check if Spotify Web API endpoint is reachable. | ||
healthInfo["api_endpoint_reachable"] = system_health.async_check_can_reach_url(hass, "https://api.spotify.com") | ||
|
||
# trace. | ||
_logsi.LogDictionary(SILevel.Verbose, "System Health results", healthInfo) | ||
|
||
# return system health data. | ||
return healthInfo | ||
|
||
except Exception as ex: | ||
|
||
# trace. | ||
_logsi.LogException("system_health_info exception: %s" % str(ex), ex, logToSystemLogger=False) | ||
raise | ||
|
||
finally: | ||
|
||
# trace. | ||
_logsi.LeaveMethod(SILevel.Debug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
pip>=21.0,<23.4 | ||
colorlog==6.7.0 | ||
homeassistant==2023.10.5 | ||
homeassistant==2024.5.0 | ||
ruff==0.1.3 | ||
smartinspectPython>=3.0.33 | ||
spotifywebapiPython==1.0.43 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters