Bump pyhomeworks to 1.0.0 (#122867)

This commit is contained in:
Erik Montnemery 2024-07-30 19:39:53 +02:00 committed by GitHub
parent 5eff4f9816
commit 94c0b9fc06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 26 additions and 16 deletions

View File

@ -8,6 +8,7 @@ from dataclasses import dataclass
import logging
from typing import Any
from pyhomeworks import exceptions as hw_exceptions
from pyhomeworks.pyhomeworks import HW_BUTTON_PRESSED, HW_BUTTON_RELEASED, Homeworks
import voluptuous as vol
@ -141,15 +142,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
dispatcher_send(hass, signal, msg_type, values)
config = entry.options
controller = Homeworks(config[CONF_HOST], config[CONF_PORT], hw_callback)
try:
controller = await hass.async_add_executor_job(
Homeworks, config[CONF_HOST], config[CONF_PORT], hw_callback
)
except (ConnectionError, OSError) as err:
await hass.async_add_executor_job(controller.connect)
except hw_exceptions.HomeworksException as err:
_LOGGER.debug("Failed to connect: %s", err, exc_info=True)
raise ConfigEntryNotReady from err
controller.start()
def cleanup(event: Event) -> None:
controller.close()
controller.stop()
entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, cleanup))
@ -176,7 +178,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
for keypad in data.keypads.values():
keypad.unsubscribe()
await hass.async_add_executor_job(data.controller.close)
await hass.async_add_executor_job(data.controller.stop)
return unload_ok

View File

@ -6,6 +6,7 @@ from functools import partial
import logging
from typing import Any
from pyhomeworks import exceptions as hw_exceptions
from pyhomeworks.pyhomeworks import Homeworks
import voluptuous as vol
@ -128,18 +129,18 @@ async def _try_connection(user_input: dict[str, Any]) -> None:
"Trying to connect to %s:%s", user_input[CONF_HOST], user_input[CONF_PORT]
)
controller = Homeworks(host, port, lambda msg_types, values: None)
controller.connect()
controller.close()
controller.join()
hass = async_get_hass()
try:
await hass.async_add_executor_job(
_try_connect, user_input[CONF_HOST], user_input[CONF_PORT]
)
except ConnectionError as err:
except hw_exceptions.HomeworksConnectionFailed as err:
raise SchemaFlowError("connection_error") from err
except Exception as err:
_LOGGER.exception("Caught unexpected exception")
_LOGGER.exception("Caught unexpected exception %s")
raise SchemaFlowError("unknown_error") from err

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/homeworks",
"iot_class": "local_push",
"loggers": ["pyhomeworks"],
"requirements": ["pyhomeworks==0.0.6"]
"requirements": ["pyhomeworks==1.0.0"]
}

View File

@ -1903,7 +1903,7 @@ pyhiveapi==0.5.16
pyhomematic==0.1.77
# homeassistant.components.homeworks
pyhomeworks==0.0.6
pyhomeworks==1.0.0
# homeassistant.components.ialarm
pyialarm==2.2.0

View File

@ -1517,7 +1517,7 @@ pyhiveapi==0.5.16
pyhomematic==0.1.77
# homeassistant.components.homeworks
pyhomeworks==0.0.6
pyhomeworks==1.0.0
# homeassistant.components.ialarm
pyialarm==2.2.0

View File

@ -2,6 +2,7 @@
from unittest.mock import ANY, MagicMock
from pyhomeworks import exceptions as hw_exceptions
import pytest
from pytest_unordered import unordered
@ -55,7 +56,7 @@ async def test_user_flow(
}
mock_homeworks.assert_called_once_with("192.168.0.1", 1234, ANY)
mock_controller.close.assert_called_once_with()
mock_controller.join.assert_called_once_with()
mock_controller.join.assert_not_called()
async def test_user_flow_already_exists(
@ -96,7 +97,10 @@ async def test_user_flow_already_exists(
@pytest.mark.parametrize(
("side_effect", "error"),
[(ConnectionError, "connection_error"), (Exception, "unknown_error")],
[
(hw_exceptions.HomeworksConnectionFailed, "connection_error"),
(Exception, "unknown_error"),
],
)
async def test_user_flow_cannot_connect(
hass: HomeAssistant,

View File

@ -2,6 +2,7 @@
from unittest.mock import ANY, MagicMock
from pyhomeworks import exceptions as hw_exceptions
from pyhomeworks.pyhomeworks import HW_BUTTON_PRESSED, HW_BUTTON_RELEASED
import pytest
@ -41,7 +42,9 @@ async def test_config_entry_not_ready(
mock_homeworks: MagicMock,
) -> None:
"""Test the Homeworks configuration entry not ready."""
mock_homeworks.side_effect = ConnectionError
mock_homeworks.return_value.connect.side_effect = (
hw_exceptions.HomeworksConnectionFailed
)
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
@ -187,4 +190,4 @@ async def test_cleanup_on_ha_shutdown(
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()
mock_controller.close.assert_called_once_with()
mock_controller.stop.assert_called_once_with()