* Create config_flow.py
* Update __init__.py
* Create const.py
* Create strings.json
* Update sensor.py
* Update manifest.json
* Update manifest.json
* Add device name to entities
* Correcting health sensor
* Update manifest.json
* Adding integration_type
* Update sensor.py
* Update __init__.py
* Enums
* Update sensor.py
* Removed unused notify_create
* Switch to SensorDeviceClass.TEMPERATURE
* Update enums
* Remove SENSOR_TYPES from const.py
* Add SENSOR_TYPES to sensor.py
* Removed dependancies
* Removed import yaml
* Removed entity_registry_enabled_default
* Update const.py remove dups
* Update manifest.json removed dups
* Update __init__.py
* Update const.py
* Update manifest.json
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py remove unused
* Update sensor.py add docstring
* Update sensor.py add super
* Remove FOLDER sensors
* Remove VOLUME_NAME
* fix cli
* fix cli
* Add config flow tests
* Update requirements_test_all.txt
* Update CODEOWNERS
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update __init__.py
Change unload to walrus
Remove async_setup
* Update const.py remove PLATFORMS
* Update __init__.py add Platform Enum
As per epenet
* Update __init__.py
* Update config_flow.py
* Update sensor.py
* Update __init__.py
ruff
* Update config_flow.py
Ruff
* Update sensor.py
* Update const.py remove attrs
* Update sensor.py add attrs
* Revert tuple for sensor extend
* Update sensor.py
* Update coordinator.py
* Update coordinator.py
* Update sensor.py
* Update coordinator.py
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update coordinator.py
* Update __init__.py
* Update coordinator.py
* Update sensor.py
* Add device_info
* Update sensor.py
* Update sensor.py self._attr_unique_id
* Update sensor.py
* Update sensor.py
* Type Hints
* Move tuples
* Drive sensor name
* Remove caps
* Remove caps
* Add YAML import
* Update sensor.py fix ruff
* Revert tuples
* Update sensor.py as per review
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* assert uid is not None
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update .coveragerc
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update sensor.py
* Update config_flow.py add imports
* Update const.py
* Update sensor.py move confs to const
* Update config_flow.py add const
* Update test_config_flow.py remove const name
* Update test_config_flow.py remove standard result const
* Update test_config_flow.py
* Combine tests
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update test_config_flow.py
* Update sensor.py change UID as requested
* Update sensor.py added check for monitor_device
* fix tests
* Remove rounding
* Revert "Remove rounding"
This reverts commit 61bf653c06
.
---------
Co-authored-by: starkillerOG <starkiller.og@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
59 lines
2 KiB
Python
59 lines
2 KiB
Python
"""Data coordinator for the qnap integration."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
import logging
|
|
from typing import Any
|
|
|
|
from qnapstats import QNAPStats
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import (
|
|
CONF_HOST,
|
|
CONF_PASSWORD,
|
|
CONF_PORT,
|
|
CONF_SSL,
|
|
CONF_TIMEOUT,
|
|
CONF_USERNAME,
|
|
CONF_VERIFY_SSL,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
|
|
from .const import DOMAIN
|
|
|
|
UPDATE_INTERVAL = timedelta(minutes=1)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class QnapCoordinator(DataUpdateCoordinator[dict[str, dict[str, Any]]]):
|
|
"""Custom coordinator for the qnap integration."""
|
|
|
|
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
|
"""Initialize the qnap coordinator."""
|
|
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
|
|
|
|
protocol = "https" if config_entry.data[CONF_SSL] else "http"
|
|
self._api = QNAPStats(
|
|
f"{protocol}://{config_entry.data.get(CONF_HOST)}",
|
|
config_entry.data.get(CONF_PORT),
|
|
config_entry.data.get(CONF_USERNAME),
|
|
config_entry.data.get(CONF_PASSWORD),
|
|
verify_ssl=config_entry.data.get(CONF_VERIFY_SSL),
|
|
timeout=config_entry.data.get(CONF_TIMEOUT),
|
|
)
|
|
|
|
def _sync_update(self) -> dict[str, dict[str, Any]]:
|
|
"""Get the latest data from the Qnap API."""
|
|
return {
|
|
"system_stats": self._api.get_system_stats(),
|
|
"system_health": self._api.get_system_health(),
|
|
"smart_drive_health": self._api.get_smart_disk_health(),
|
|
"volumes": self._api.get_volumes(),
|
|
"bandwidth": self._api.get_bandwidth(),
|
|
}
|
|
|
|
async def _async_update_data(self) -> dict[str, dict[str, Any]]:
|
|
"""Get the latest data from the Qnap API."""
|
|
return await self.hass.async_add_executor_job(self._sync_update)
|