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

Improve formatting #41

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions custom_components/kamstrup_403/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"""
import asyncio
from datetime import timedelta
from typing import Any, List
import logging
import serial
from typing import Any, List

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PORT, CONF_SCAN_INTERVAL
Expand All @@ -17,8 +16,7 @@
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .kamstrup import Kamstrup
import serial

from .const import (
DEFAULT_BAUDRATE,
Expand All @@ -29,6 +27,7 @@
PLATFORMS,
VERSION,
)
from .kamstrup import Kamstrup

_LOGGER: logging.Logger = logging.getLogger(__package__)

Expand Down
11 changes: 3 additions & 8 deletions custom_components/kamstrup_403/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
from homeassistant import config_entries
from homeassistant.const import CONF_PORT, CONF_SCAN_INTERVAL, CONF_TIMEOUT
from homeassistant.core import callback
import voluptuous as vol
import serial
import voluptuous as vol

from .const import (
DEFAULT_BAUDRATE,
DEFAULT_SCAN_INTERVAL,
DEFAULT_TIMEOUT,
DOMAIN,
)
from .const import DEFAULT_BAUDRATE, DEFAULT_SCAN_INTERVAL, DEFAULT_TIMEOUT, DOMAIN


class KamstrupFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
Expand Down Expand Up @@ -79,7 +74,7 @@ class KamstrupOptionsFlowHandler(config_entries.OptionsFlow):
"""Kamstrup config flow options handler."""

def __init__(self, config_entry):
"""Initialize HACS options flow."""
"""Initialize options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options)

Expand Down
3 changes: 1 addition & 2 deletions custom_components/kamstrup_403/kamstrup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#
# Modified by Sander Gols to integrate in HA component

from __future__ import print_function
import math

import serial
import math

#######################################################################
# Units, provided by Erik Jensen
Expand Down
10 changes: 3 additions & 7 deletions custom_components/kamstrup_403/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
"issue_tracker": "https://github.com/golles/ha-kamstrup_403/issues",
"version": "2.0.0",
"config_flow": true,
"codeowners": [
"@golles"
],
"requirements": [
"pyserial==3.5"
]
}
"codeowners": ["@golles"],
"requirements": ["pyserial==3.5"]
}
7 changes: 3 additions & 4 deletions custom_components/kamstrup_403/sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""Sensor platform for kamstrup_403."""

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import VOLUME_CUBIC_METERS
from homeassistant.core import HomeAssistant
from homeassistant.components.sensor import (
DOMAIN as SENSOR_DOMAIN,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import VOLUME_CUBIC_METERS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
homeassistant
pyserial
pyserial==3.5
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest-homeassistant-custom-component==0.10.4
pyserial
pytest-homeassistant-custom-component
pyserial==3.5
4 changes: 2 additions & 2 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constants for kamstrup_403 tests."""
from homeassistant.const import CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.const import CONF_PORT, CONF_SCAN_INTERVAL, CONF_TIMEOUT

# Mock config data to be used across multiple tests
MOCK_CONFIG = {CONF_PORT: "/dev/ttyUSB0"}
MOCK_UPDATE_CONFIG = {CONF_SCAN_INTERVAL: 120}
MOCK_UPDATE_CONFIG = {CONF_SCAN_INTERVAL: 120, CONF_TIMEOUT: 1.0}
8 changes: 3 additions & 5 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
from unittest.mock import patch

from homeassistant import config_entries, data_entry_flow
from homeassistant.const import CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.const import CONF_PORT
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.kamstrup_403.const import DOMAIN, SENSOR

from .const import MOCK_CONFIG, MOCK_UPDATE_CONFIG


# This fixture bypasses the actual setup of the integration
# since we only want to test the config flow. We test the
# actual functionality of the integration in other test modules.
@pytest.fixture(autouse=True)
def bypass_setup_fixture():
"""Prevent setup."""
with patch(
"custom_components.kamstrup_403.async_setup",
return_value=True,
), patch(
with patch("custom_components.kamstrup_403.async_setup", return_value=True,), patch(
"custom_components.kamstrup_403.async_setup_entry",
return_value=True,
):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Test kamstrup_403 setup process."""
from homeassistant.exceptions import ConfigEntryNotReady
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.kamstrup_403 import (
Expand Down
27 changes: 27 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Test for versions."""
import json

from custom_components.kamstrup_403.const import VERSION

with open(
file="custom_components/kamstrup_403/manifest.json", mode="r", encoding="UTF-8"
) as manifest_file:
data = manifest_file.read()

manifest = json.loads(data)


async def test_component_version():
"""Verify that the version in the manifest and const.py are equal"""
assert manifest["version"] == VERSION


async def test_component_requirements():
"""Verify that all requirements in the manifest.json are defined as in the requirements files"""
requirements_files = ["requirements_dev.txt", "requirements_test.txt"]
for requirements_file in requirements_files:
with open(file=requirements_file, mode="r", encoding="UTF-8") as file:
lines = [line.rstrip("\n") for line in file]

for requirement in manifest["requirements"]:
assert requirement in lines