Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre core #11

Open
wants to merge 133 commits into
base: dev-discovery
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
a83a4fd
Update Native unit of measurement
disforw Jan 5, 2023
b54d25b
Update const.py
disforw Jan 5, 2023
5edfab5
Update const.py
disforw Jan 7, 2023
948e0d8
Update sensor.py
disforw Jan 13, 2023
a44d6f1
Update manifest.json
disforw Feb 9, 2023
624dd53
Update sensor.py
disforw Feb 9, 2023
cc9a475
Update README.md
disforw Mar 26, 2023
0cd09e6
Update const.py
disforw Mar 26, 2023
43d966b
Removed notify_create unused
disforw May 31, 2023
ec7f571
Remove QNapSensorEntityDescription
disforw May 31, 2023
a2f6247
Add SENSOR_TYPES
disforw May 31, 2023
19a1a54
Remove SENSOR_TYPES
disforw May 31, 2023
56b0f78
Update sensor.py
disforw May 31, 2023
c50669b
Update const.py
disforw Jun 1, 2023
e943d11
Update sensor.py
disforw Jun 1, 2023
5a157d9
Update sensor.py
disforw Jun 1, 2023
8e26fea
Update manifest.json
disforw Jun 1, 2023
2592bcb
Update __init__.py
disforw Jun 1, 2023
61991aa
Update __init__.py
disforw Jun 1, 2023
5c46a35
Update manifest.json
disforw Jun 2, 2023
54fc65d
Update sensor.py
disforw Jun 2, 2023
abcd8aa
Update sensor.py
disforw Jun 2, 2023
0a04626
Update sensor.py
disforw Jun 2, 2023
8a6110c
Update sensor.py remove coordinator
disforw Jun 2, 2023
f70c1a1
Update sensor.py readd coordinator_context
disforw Jun 2, 2023
52a64dd
Update sensor.py add super()
disforw Jun 2, 2023
544cb5d
Update sensor.py remove super
disforw Jun 2, 2023
6797e59
Create sensor.bak
disforw Jun 2, 2023
7cd933e
Removed folder sensors
disforw Jun 2, 2023
bab3218
Create hassfest.yaml
disforw Jun 3, 2023
938b739
Update manifest.json sorting
disforw Jun 3, 2023
00e12ae
Create code-quality.yml
disforw Jun 3, 2023
2ca759c
Update sensor.py
disforw Jun 3, 2023
ab7b89f
Update and rename code-quality.yml to code-quality.yxx
disforw Jun 3, 2023
05004ea
Delete code-quality.yxx
disforw Jun 3, 2023
2cd2b4a
Update manifest.json
disforw Jun 3, 2023
3217852
Update __init__.py
disforw Jun 3, 2023
1cf119c
Update sensor.py
disforw Jun 3, 2023
c11f4b3
Update config_flow.py
disforw Jun 3, 2023
e4c7ec8
Update const.py
disforw Jun 3, 2023
c7858a7
Delete hassfest.yaml
disforw Jun 3, 2023
f57987d
Update README.md
disforw Jun 3, 2023
b46a25a
Update README.md
disforw Jun 3, 2023
141829e
Update sensor.py
disforw Jun 3, 2023
55ed345
Remove import
disforw Jun 6, 2023
d08cf60
Change unload
disforw Jun 6, 2023
a531d29
Add Platform Enum
disforw Jun 6, 2023
8a4eb85
Remove Platforms
disforw Jun 6, 2023
39866b3
Update __init__.py remove coordinator
disforw Jun 10, 2023
1a5e812
Create coordinator.py
disforw Jun 10, 2023
02d2a3a
Update coordinator.py
disforw Jun 10, 2023
808ac32
Update __init__.py
disforw Jun 10, 2023
b040046
Update coordinator.py
disforw Jun 10, 2023
ce70556
Remove unused imports
disforw Jun 10, 2023
58ff533
Fix hass
disforw Jun 10, 2023
726f6f7
Merge pull request #8 from disforw/dev-coordinator
disforw Jun 10, 2023
4c41aa9
Fix coord as per review
disforw Jun 12, 2023
9e55061
Fix coordinator.py as per review
disforw Jun 12, 2023
c833bd2
Update coordinator.py
disforw Jun 12, 2023
a80bf08
Update coordinator.py
disforw Jun 12, 2023
29f1fb1
Update coordinator.py
disforw Jun 12, 2023
818f7c4
Update coordinator.py
disforw Jun 13, 2023
bc4b6a8
Update sensor.py
disforw Jun 13, 2023
07b2f9d
Update __init__.py
disforw Jun 13, 2023
6fd8ec0
Update __init__.py
disforw Jun 13, 2023
04cacaf
Update sensor.py
disforw Jun 13, 2023
411df6b
Update __init__.py
disforw Jun 13, 2023
4b2a5ca
Update __init__.py
disforw Jun 13, 2023
6ef3400
Update coordinator.py
disforw Jun 13, 2023
ac1982c
Update __init__.py
disforw Jun 13, 2023
8c88b57
Update config_flow.py
disforw Jun 13, 2023
6397341
Update sensor.py
disforw Jun 13, 2023
5c15ec5
Update __init__.py
disforw Jun 13, 2023
401e387
Update __init__.py
disforw Jun 13, 2023
85f6809
Update coordinator.py
disforw Jun 13, 2023
c90478f
Update sensor.py
disforw Jun 13, 2023
1c74f30
Update sensor.py
disforw Jun 13, 2023
9f15b41
Create hassfest.yaml
disforw Jun 14, 2023
b0edd4b
Create code-quality.yml
disforw Jun 14, 2023
ee61c8e
Update code-quality.yml
disforw Jun 14, 2023
c6d9cf9
Create ruff.yaml
disforw Jun 14, 2023
608350e
Delete code-quality.yml
disforw Jun 14, 2023
f4a4a56
Delete hassfest.yaml
disforw Jun 14, 2023
ef448ea
Create Ci.yaml
disforw Jun 14, 2023
6970a56
Delete Ci.yaml
disforw Jun 14, 2023
1ee02f2
Update ruff.yaml
disforw Jun 14, 2023
1db8925
Update __init__.py
disforw Jun 14, 2023
4c02d38
Update config_flow.py
disforw Jun 14, 2023
fc94ff4
Update ruff.yaml
disforw Jun 14, 2023
0372fd2
Update ruff.yaml
disforw Jun 14, 2023
ded3e96
Create black.yaml
disforw Jun 14, 2023
9566886
Create pylint.yaml
disforw Jun 14, 2023
2c453cd
Update ruff.yaml
disforw Jun 14, 2023
fd3c0b3
Update __init__.py
disforw Jun 14, 2023
64017f8
Update config_flow.py
disforw Jun 14, 2023
6a55fae
Update sensor.py
disforw Jun 14, 2023
e191a05
Update sensor.py
disforw Jun 14, 2023
f32f9ff
Update const.py
disforw Jun 14, 2023
c5e6558
Update sensor.py
disforw Jun 14, 2023
1c1c7f6
Update sensor.py
disforw Jun 14, 2023
0b757a5
Update sensor.py
disforw Jun 14, 2023
50ded89
Update coordinator.py
disforw Jun 15, 2023
4cea1ff
Update __init__.py
disforw Jun 15, 2023
9d21a48
Update const.py
disforw Jun 15, 2023
4fe103e
Update __init__.py
disforw Jun 15, 2023
887cf94
Update coordinator.py
disforw Jun 15, 2023
f7d2e0d
Update coordinator.py
disforw Jun 15, 2023
3a9579b
Update sensor.py
disforw Jun 15, 2023
6da23c8
Update sensor.py
disforw Jun 15, 2023
c557f12
Update sensor.py
disforw Jun 15, 2023
5e7bd87
Update sensor.py
disforw Jun 15, 2023
fba7fde
Update __init__.py
disforw Jun 15, 2023
1ac0ed5
Update sensor.py
disforw Jun 15, 2023
62aa766
Update sensor.py
disforw Jun 15, 2023
2392043
Update sensor.py
disforw Jun 15, 2023
e8a2c36
Update sensor.py
disforw Jun 15, 2023
6c5cb48
Type hints
disforw Jun 16, 2023
a834cf5
Move sensor description
disforw Jun 16, 2023
2914ec2
Delete black.yaml
disforw Jun 16, 2023
e0a64bb
Delete pylint.yaml
disforw Jun 16, 2023
4ecac16
Delete ruff.yaml
disforw Jun 16, 2023
f6ddc58
Create hassfest.yml
disforw Jun 24, 2023
63dd566
Create hacs.yml
disforw Jun 24, 2023
8b929eb
Update hacs.json
disforw Jun 24, 2023
de66473
Update manifest.json
disforw Jun 24, 2023
600e6be
Update hacs.json
disforw Jun 24, 2023
8c0392c
Create tests
disforw Jun 24, 2023
9c12581
Rename tests to testss/test_config_flow.py
disforw Jun 24, 2023
c982ec8
Delete hacs.yml
disforw Jun 25, 2023
c0799fb
Delete test_config_flow.py
disforw Jun 27, 2023
0c56eb5
Create time.py
disforw Jun 28, 2023
3167c0f
Update time.py
disforw Jun 28, 2023
35a1979
Delete time.py
disforw Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/hassfest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Validate with hassfest

on:

push:

pull_request:

schedule:

- cron: '0 0 * * *'

jobs:

validate:

runs-on: "ubuntu-latest"

steps:

- uses: "actions/checkout@v3"

- uses: "home-assistant/actions/hassfest@master"
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# QNAP NAP Integration
# QNAP Integration Re-write with Config-Flow

This is a complete re-write of the Core QNAP integration, adding config_flow and unique_ID. Using this custom componant for development and testing before creating a PR and adding to Core.
This is a complete re-write of the Core QNAP integration, adding config_flow and unique_ID. Using this custom componant will override the built-in QNAP integration.
This integration has been submitted and accepted as a PR to Home Assistant Core. I will leave this custom_integration open, active, and in sync with the core version so I can continue to develop on it. Here are some upcoming features (that are not submitted to core).
* Folder entites
* Firmware update entity
* auto-discovery of device

## Looking for contributers, testers, and ideas...
## Installation

Due to this repository overriding an existing core integration, it will need to be added as a custom repository. Goto HACS - Custom Integrations - three dots at the top - Custom Repositories.
Paste: https://github.com/disforw/qnap


NOTE: All folder and drive entities will be disabled by default. You will need to go to the entities you want and enable them manually.
97 changes: 17 additions & 80 deletions custom_components/qnap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,34 @@
"""The qnap component."""
from datetime import timedelta
import logging
from __future__ import annotations

from qnapstats import QNAPStats
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady

from homeassistant import config_entries
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_SSL,
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.helpers import config_per_platform
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import DOMAIN
from .coordinator import QnapCoordinator

from .const import DEFAULT_PORT, DEFAULT_TIMEOUT, DOMAIN, PLATFORMS
PLATFORMS: list[Platform] = [
Platform.SENSOR,
]

UPDATE_INTERVAL = timedelta(minutes=1)

_LOGGER = logging.getLogger(__name__)


async def async_setup(hass, config):
"""Set up the qnap environment."""
hass.data.setdefault(DOMAIN, {})

# Import configuration from sensor platform
config_platform = config_per_platform(config, "sensor")
for p_type, p_config in config_platform:
if p_type != DOMAIN:
continue

hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=p_config,
)
)

return True


async def async_setup_entry(hass, config_entry):
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set the config entry up."""
host = config_entry.data[CONF_HOST]
protocol = "https" if config_entry.data.get(CONF_SSL) else "http"
api = QNAPStats(
host=f"{protocol}://{host}",
port=config_entry.data.get(CONF_PORT, DEFAULT_PORT),
username=config_entry.data[CONF_USERNAME],
password=config_entry.data[CONF_PASSWORD],
verify_ssl=config_entry.data.get(CONF_VERIFY_SSL),
timeout=DEFAULT_TIMEOUT,
)

async def async_update_data():
datas = {}
datas["system_stats"] = await hass.async_add_executor_job(api.get_system_stats)
datas["system_health"] = await hass.async_add_executor_job(api.get_system_health)
datas["smart_drive_health"] = await hass.async_add_executor_job(api.get_smart_disk_health)
datas["volumes"] = await hass.async_add_executor_job(api.get_volumes)
datas["bandwidth"] = await hass.async_add_executor_job(api.get_bandwidth)
return datas

coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name="sensor",
update_method=async_update_data,
update_interval=UPDATE_INTERVAL,
)

hass.data.setdefault(DOMAIN, {})
coordinator = QnapCoordinator(hass, config_entry)
# Fetch initial data so we have data when entities subscribe
await coordinator.async_config_entry_first_refresh()

hass.data[DOMAIN][config_entry.entry_id] = coordinator

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, component)
)

await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
return True


async def async_unload_entry(hass, config_entry):
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(
if unload_ok := await hass.config_entries.async_unload_platforms(
config_entry, PLATFORMS
)
if unload_ok:
):
hass.data[DOMAIN].pop(config_entry.entry_id)
return unload_ok
41 changes: 23 additions & 18 deletions custom_components/qnap/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Config flow to configure qnap component."""
from __future__ import annotations

import logging
from typing import Any

from qnapstats import QNAPStats
from requests.exceptions import ConnectTimeout
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components.persistent_notification import create as notify_create
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
Expand All @@ -15,17 +17,24 @@
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_validation as cv

from .const import DEFAULT_PORT, DEFAULT_TIMEOUT, DOMAIN
from .const import (
DEFAULT_PORT,
DEFAULT_SSL,
DEFAULT_TIMEOUT,
DEFAULT_VERIFY_SSL,
DOMAIN,
)

DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_SSL, default=False): cv.boolean,
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
}
)
Expand All @@ -38,27 +47,28 @@ class QnapConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

def __init__(self):
"""Initialize."""
self.is_imported = False

async def async_step_import(self, import_info):
"""Set the config entry up from yaml."""
self.is_imported = True
return await self.async_step_user(import_info)

async def async_step_user(self, user_input=None):
async def async_step_user(
self,
user_input: dict[str, Any] | None = None,
) -> FlowResult:
"""Handle a flow initialized by the user."""
errors = {}
if user_input is not None:
user_input.setdefault(CONF_SSL, DEFAULT_SSL)
user_input.setdefault(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL)
user_input.setdefault(CONF_PORT, DEFAULT_PORT)
host = user_input[CONF_HOST]
protocol = "https" if user_input.get(CONF_SSL, False) else "http"
protocol = "https" if user_input[CONF_SSL] else "http"
api = QNAPStats(
host=f"{protocol}://{host}",
port=user_input.get(CONF_PORT, DEFAULT_PORT),
port=user_input[CONF_PORT],
username=user_input[CONF_USERNAME],
password=user_input[CONF_PASSWORD],
verify_ssl=user_input.get(CONF_VERIFY_SSL, True),
verify_ssl=user_input[CONF_VERIFY_SSL],
timeout=DEFAULT_TIMEOUT,
)
try:
Expand All @@ -75,11 +85,6 @@ async def async_step_user(self, user_input=None):
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()
title = stats["system"]["name"].capitalize()
if self.is_imported:
_LOGGER.warning(
"The import of the QNAP configuration was successful. \
Please remove the platform from the YAML configuration file"
)
return self.async_create_entry(title=title, data=user_input)

return self.async_show_form(
Expand Down
Loading