clean update function, minimise comments to the useful bits

This commit is contained in:
pssc
2024-07-25 14:13:14 +01:00
parent 41b9d7d7b5
commit 4d00e73383

View File

@@ -51,23 +51,26 @@ class LMSStatusDataUpdateCoordinator(DataUpdateCoordinator):
if not data:
raise UpdateFailed("No data from status poll")
_LOGGER.debug("Raw serverstatus %s=%s", self.my_api.name, data)
# Sensor that need special handling
return self._prepare_status_data(data)
def _prepare_status_data(self, data: dict) -> dict:
"""Sensors that need the data changing for HA presentation."""
# 'lastscan': '1718431678', epoc -> ISO 8601 not always present
data[STATUS_SENSOR_LASTSCAN] = (
STATUS_SENSOR_LASTSCAN in data
and dt_util.utc_from_timestamp(int(data[STATUS_SENSOR_LASTSCAN]))
or None
)
# rescan # bool are we rescanning alter poll not always present
# rescan bool are we rescanning alter poll not always present
data[STATUS_SENSOR_RESCAN] = STATUS_SENSOR_RESCAN in data and True or False
# needsrestart bool plugin updates... not always present
data[STATUS_SENSOR_NEEDSRESTART] = (
STATUS_SENSOR_NEEDSRESTART in data and True or False
)
# newversion str not always present
# Sample text 'A new version of Logitech Media Server is available (8.5.2 - 0). <a href="updateinfo.html?installerFile=/var/lib/squeezeboxserver/cache/updates/logitechmediaserver_8.5.2_amd64.deb" target="update">Click here for further information</a>.'
# newversion str not always present and we wish to remove the link supplied for now
data[STATUS_SENSOR_NEWVERSION] = (
STATUS_SENSOR_NEWVERSION in data
and self.newversion_regex.sub("...", data[STATUS_SENSOR_NEWVERSION])
@@ -77,10 +80,4 @@ class LMSStatusDataUpdateCoordinator(DataUpdateCoordinator):
data[STATUS_SENSOR_NEWPLUGINS] = (
STATUS_SENSOR_NEWPLUGINS in data and data[STATUS_SENSOR_NEWPLUGINS] or None
)
# "info total duration" in fractions of seconds
# progressdone Returned with the current value of items completed for current scan phase. Not returned if no scan is in progress.
# progresstotal Returned with the total value of items found for current scan phase. Not returned if no scan is in progress.
# lastscanfailed Information about a possible failure in case a scan has not finished in an attended manner.
_LOGGER.debug("Processed serverstatus %s=%s", self.my_api.name, data)
return data