8000 Allow hostname for nibe heatpump by elupus · Pull Request #80793 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow hostname for nibe heatpump #80793

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

Merged
merged 1 commit into from
Oct 24, 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 homeassistant/components/nibe_heatpump/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import errno
from socket import gaierror
from typing import Any

from nibe.connection.nibegw import NibeGW
Expand All @@ -14,7 +15,6 @@
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_validation as cv
from homeassistant.util.network import is_ipv4_address

from .const import (
CONF_CONNECTION_TYPE,
Expand Down Expand Up @@ -51,9 +51,6 @@ def __init__(self, message: str, field: str, error: str) -> None:
async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect."""

if not is_ipv4_address(data[CONF_IP_ADDRESS]):
raise FieldError("Not a valid ipv4 address", CONF_IP_ADDRESS, "address")

heatpump = HeatPump(Model[data[CONF_MODEL]])
heatpump.initialize()

Expand All @@ -79,6 +76,8 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
coil = await connection.read_coil(coil)
word_swap = coil.value == "ON"
coil = await connection.write_coil(coil)
except gaierror as exception:
raise FieldError(str(exception), "ip_address", "address") from exception
except CoilNotFoundException as exception:
raise FieldError(
"Model selected doesn't seem to support expected coils", "base", "model"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/nibe_heatpump/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"step": {
"user": {
"data": {
"ip_address": "Remote IP address",
"ip_address": "Remote address",
"remote_read_port": "Remote read port",
"remote_write_port": "Remote write port",
"listening_port": "Local listening port"
Expand All @@ -13,7 +13,7 @@
"error": {
"write": "Error on write request to pump. Verify your `Remote write port` or `Remote IP address`.",
"read": "Error on read request from pump. Verify your `Remote read port` or `Remote IP address`.",
"address": "Invalid remote IP address specified. Address must be a IPV4 address.",
"address": "Invalid remote address specified. Address must be an IP address or a resolvable hostname.",
"address_in_use": "The selected listening port is already in use on this system.",
"model": "The model selected doesn't seem to support modbus40",
"unknown": "[%key:common::config_flow::error::unknown%]"
Expand Down
7 changes: 2 additions & 5 deletions homeassistant/components/nibe_heatpump/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"config": {
"abort": {
"already_configured": "Device is already configured"
},
"error": {
"address": "Invalid remote IP address specified. Address must be a IPV4 address.",
"address": "Invalid remote address specified. Address must be an IP address or a resolvable hostname.",
"address_in_use": "The selected listening port is already in use on this system.",
"model": "The model selected doesn't seem to support modbus40",
"read": "Error on read request from pump. Verify your `Remote read port` or `Remote IP address`.",
Expand All @@ -14,7 +11,7 @@
"step": {
"user": {
"data": {
"ip_address": "Remote IP address",
"ip_address": "Remote address",
"listening_port": "Local listening port",
"remote_read_port": "Remote read port",
"remote_write_port": "Remote write port"
Expand Down
5 changes: 3 additions & 2 deletions tests/components/nibe_heatpump/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the Nibe Heat Pump config flow."""
import errno
from socket import gaierror
from unittest.mock import Mock, patch

from nibe.coil import Coil
Expand Down Expand Up @@ -150,13 +151,13 @@ async def test_unexpected_exception(hass: HomeAssistant, mock_connection: Mock)
assert result2["errors"] == {"base": "unknown"}


async def test_invalid_ip(hass: HomeAssistant, mock_connection: Mock) -> None:
async def test_invalid_host(hass: HomeAssistant, mock_connection: Mock) -> None:
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

mock_connection.return_value.read_coil.side_effect = Exception()
mock_connection.return_value.read_coil.side_effect = gaierror()

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {**MOCK_FLOW_USERDATA, "ip_address": "abcd"}
Expand Down
0