mirror of
https://github.com/Andre0512/hon.git
synced 2024-01-19 02:50:19 +00:00
Create data archive
This commit is contained in:
parent
4b1f500f90
commit
e5e351272b
|
@ -1,18 +1,17 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import voluptuous as vol
|
||||
from pyhon import Hon
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.helpers import config_validation as cv, aiohttp_client
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from pyhon import Hon
|
||||
|
||||
from .const import DOMAIN, PLATFORMS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
HON_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_EMAIL): cv.string,
|
||||
|
@ -29,7 +28,10 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||
session = aiohttp_client.async_get_clientsession(hass)
|
||||
hon = await Hon(
|
||||
entry.data["email"], entry.data["password"], session=session
|
||||
entry.data["email"],
|
||||
entry.data["password"],
|
||||
session=session,
|
||||
test_data_path=Path(hass.config.config_dir),
|
||||
).create()
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.unique_id] = hon
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import pkg_resources
|
||||
from homeassistant.components import persistent_notification
|
||||
|
@ -61,7 +62,8 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
entity = HonButtonEntity(hass, entry, device, description)
|
||||
await entity.coordinator.async_config_entry_first_refresh()
|
||||
entities.append(entity)
|
||||
entities.append(HonFeatureRequestButton(hass, entry, device))
|
||||
entities.append(HonDeviceInfo(hass, entry, device))
|
||||
entities.append(HonDataArchive(hass, entry, device))
|
||||
await entities[-1].coordinator.async_config_entry_first_refresh()
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -82,21 +84,41 @@ class HonButtonEntity(HonEntity, ButtonEntity):
|
|||
)
|
||||
|
||||
|
||||
class HonFeatureRequestButton(HonEntity, ButtonEntity):
|
||||
class HonDeviceInfo(HonEntity, ButtonEntity):
|
||||
def __init__(self, hass, entry, device: HonAppliance) -> None:
|
||||
super().__init__(hass, entry, device)
|
||||
|
||||
self._attr_unique_id = f"{super().unique_id}_log_device_info"
|
||||
self._attr_unique_id = f"{super().unique_id}_show_device_info"
|
||||
self._attr_icon = "mdi:information"
|
||||
self._attr_name = "Show Device Info"
|
||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
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}"
|
||||
info = f"{self._device.diagnose}pyhOnVersion: {pyhon_version}"
|
||||
title = f"{self._device.nick_name} Device Info"
|
||||
persistent_notification.create(
|
||||
self._hass, f"````\n```\n{info}\n```\n````", title
|
||||
)
|
||||
_LOGGER.info(info.replace(" ", "\u200B "))
|
||||
|
||||
|
||||
class HonDataArchive(HonEntity, ButtonEntity):
|
||||
def __init__(self, hass, entry, device: HonAppliance) -> None:
|
||||
super().__init__(hass, entry, device)
|
||||
|
||||
self._attr_unique_id = f"{super().unique_id}_create_data_archive"
|
||||
self._attr_icon = "mdi:archive-arrow-down"
|
||||
self._attr_name = "Create Data Archive"
|
||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
|
||||
async def async_press(self) -> None:
|
||||
path = Path(self._hass.config.config_dir) / "www"
|
||||
data = await self._device.data_archive(path)
|
||||
title = f"{self._device.nick_name} Data Archive"
|
||||
text = (
|
||||
f'<a href="/local/{data}" target="_blank">{data}</a> <br/><br/> '
|
||||
f"Use this data for [GitHub Issues of Haier hOn](https://github.com/Andre0512/hon).<br/>"
|
||||
f"Or add it to the [hon-test-data collection](https://github.com/Andre0512/hon-test-data)."
|
||||
)
|
||||
persistent_notification.create(self._hass, text, title)
|
||||
|
|
Loading…
Reference in a new issue