From 60ed8b4ec1d869b45de6d2279910d821ceae2af4 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Thu, 29 Jun 2023 22:19:29 +0200 Subject: [PATCH] Read out version --- custom_components/hon/button.py | 11 ++++++--- custom_components/hon/hon.py | 37 ++++++++++++++++++++++++++--- custom_components/hon/manifest.json | 4 ++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/custom_components/hon/button.py b/custom_components/hon/button.py index 8a07b2a..9adb0b8 100644 --- a/custom_components/hon/button.py +++ b/custom_components/hon/button.py @@ -1,7 +1,6 @@ import logging from pathlib import Path -import pkg_resources from homeassistant.components import persistent_notification from homeassistant.components.button import ButtonEntityDescription, ButtonEntity from homeassistant.config_entries import ConfigEntry @@ -92,10 +91,14 @@ class HonDeviceInfo(HonEntity, ButtonEntity): self._attr_icon = "mdi:information" self._attr_name = "Show Device Info" self._attr_entity_category = EntityCategory.DIAGNOSTIC + if "beta" not in self.coordinator.info.hon_version: + self._attr_entity_registry_enabled_default = False async def async_press(self) -> None: - pyhon_version = pkg_resources.get_distribution("pyhon").version - info = f"{self._device.diagnose}pyhOnVersion: {pyhon_version}" + versions = "versions:\n" + versions += f" hon: {self.coordinator.info.hon_version}\n" + versions += f" pyhOn: {self.coordinator.info.pyhon_version}\n" + info = f"{self._device.diagnose}{versions}" title = f"{self._device.nick_name} Device Info" persistent_notification.create( self._hass, f"````\n```\n{info}\n```\n````", title @@ -111,6 +114,8 @@ class HonDataArchive(HonEntity, ButtonEntity): self._attr_icon = "mdi:archive-arrow-down" self._attr_name = "Create Data Archive" self._attr_entity_category = EntityCategory.DIAGNOSTIC + if "beta" not in self.coordinator.info.hon_version: + self._attr_entity_registry_enabled_default = False async def async_press(self) -> None: path = Path(self._hass.config.config_dir) / "www" diff --git a/custom_components/hon/hon.py b/custom_components/hon/hon.py index 40007aa..3a43678 100644 --- a/custom_components/hon/hon.py +++ b/custom_components/hon/hon.py @@ -1,7 +1,10 @@ +import json import logging from contextlib import suppress from datetime import timedelta +from pathlib import Path +import pkg_resources from homeassistant.core import callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -37,9 +40,7 @@ class HonEntity(CoordinatorEntity): return DeviceInfo( identifiers={(DOMAIN, self._device.unique_id)}, manufacturer=self._device.get("brand", ""), - name=self._device.nick_name - if self._device.nick_name - else self._device.model_name, + name=self._device.nick_name, model=self._device.model_name, sw_version=self._device.get("fwVersion", ""), ) @@ -50,6 +51,31 @@ class HonEntity(CoordinatorEntity): self.async_write_ha_state() +class HonInfo: + def __init__(self): + self._manifest = self._get_manifest() + self._hon_version = self._manifest.get("version", "") + self._pyhon_version = pkg_resources.get_distribution("pyhon").version + + @staticmethod + def _get_manifest(): + manifest = Path(__file__).parent / "manifest.json" + with open(manifest, "r", encoding="utf-8") as file: + return json.loads(file.read()) + + @property + def manifest(self): + return self._manifest + + @property + def hon_version(self): + return self._hon_version + + @property + def pyhon_version(self): + return self._pyhon_version + + class HonCoordinator(DataUpdateCoordinator): def __init__(self, hass, device: HonAppliance): """Initialize my coordinator.""" @@ -60,10 +86,15 @@ class HonCoordinator(DataUpdateCoordinator): update_interval=timedelta(seconds=UPDATE_INTERVAL), ) self._device = device + self._info = HonInfo() async def _async_update_data(self): await self._device.update() + @property + def info(self) -> HonInfo: + return self._info + def unique_entities(base_entities, new_entities): result = list(base_entities) diff --git a/custom_components/hon/manifest.json b/custom_components/hon/manifest.json index df8a178..c6d92bb 100644 --- a/custom_components/hon/manifest.json +++ b/custom_components/hon/manifest.json @@ -9,7 +9,7 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Andre0512/hon/issues", "requirements": [ - "pyhOn==0.14.4" + "pyhOn==0.14.6" ], - "version": "0.9.0-beta.6" + "version": "0.9.0-beta.7" }