* merge upstream * Update homeassistant/components/weatherflow/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * feat: Removing unused keys * feat: Addressing PR to remove DEFAULT_HOST from init * feat: Addressing PR abort case * feat: Ensure there is a default host always * feat: Addressing PR comments and fixing entity names via local testing * feat: Tested units * feat: updated variable names to hopefully add some clarity to the function * feat: added more var names for clarity * feat: Fixed abort * Update homeassistant/components/weatherflow/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * feat: Removed an unnecessary line * feat: Test updates * feat: Removed unreachable code * feat: Tons of improvements * removed debug code * feat: small tweaks * feat: Fixed density into HA Compatibility * feat: Handled the options incorrectly... now fixed * feat: Handled the options incorrectly... now fixed * Update homeassistant/components/weatherflow/manifest.json Co-authored-by: J. Nick Koston <nick@koston.org> * Cleaned up callback in __init__ Cleaning up config_flow as well * feat: Cleaned up a stupid test * feat: Simulating a timeout event * feat: Triggering timeout in mocking * feat: trying to pass tests * refactor: Moved code around so easier to test * Update homeassistant/components/weatherflow/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> * feat: Incremental changes moving along well * feat: Last fix before re-review * feat: Hopefully the tests shall pass * feat: Remove domian from unique id * feat: Fixed entity name * feat: Removed unneeded lambda - to make thread safe * Working version... * working * working * feat: Remove tuff * feat: Removed dual call * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * feat: updates based on pr * feat: removed some self refrences * feat: Mod RSSI * feat: Removed the custom Air Density (will add in a later PR) * feat: Significant cleanup of config flow * feat: Reworked the configflwo with the help of Joostlek * feat: Updated test coverage * feat: Removing bakcing lib attribute * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * feat: Updated translations * feat: Renamed CUSTOM to VOC * feat: Extreme simplification of config flow * feat: Pushing incremental changes * feat: Fixing test coverage * feat: Added lambda expressions for attributes and removed the custom AirDensity sensor * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: J. Nick Koston <nick@koston.org> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: J. Nick Koston <nick@koston.org> * feat: Removed default lambda expression from raw_data_conv_fn * feat: Added back default variable for lambda * feat: Updated tests accordingly * feat: Updated tests * made sure to patch correct import * made sure to patch correct import * feat: Fixed up tests ... added missing asserts * feat: Dropped model * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: J. Nick Koston <nick@koston.org> * Refactor: Updated code * refactor: Removed commented code * feat: close out all tests * feat: Fixing the patch * feat: Removed a bunch of stuff * feat: Cleaning up tests even more * fixed patch and paramaterized a test * feat: Addressing most recent comments * updates help of joostlek * feat: Updated coverage for const * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/weatherflow/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * feat: Addressing more PR issues... probably still a few remain * using const logger * Update homeassistant/components/weatherflow/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
"""Tests for WeatherFlow."""
|
|
|
|
import asyncio
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
from pyweatherflowudp.errors import AddressInUseError
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.components.weatherflow.const import (
|
|
DOMAIN,
|
|
ERROR_MSG_ADDRESS_IN_USE,
|
|
ERROR_MSG_CANNOT_CONNECT,
|
|
ERROR_MSG_NO_DEVICE_FOUND,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_single_instance(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_has_devices: AsyncMock,
|
|
) -> None:
|
|
"""Test more than one instance."""
|
|
mock_config_entry.add_to_hass(hass)
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
assert result["type"] == FlowResultType.ABORT
|
|
assert result["reason"] == "single_instance_allowed"
|
|
|
|
|
|
async def test_devices_with_mocks(
|
|
hass: HomeAssistant,
|
|
mock_start: AsyncMock,
|
|
mock_stop: AsyncMock,
|
|
mock_setup_entry: AsyncMock,
|
|
) -> None:
|
|
"""Test getting user input."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
assert result["data"] == {}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("exception", "error_msg"),
|
|
[
|
|
(asyncio.TimeoutError, ERROR_MSG_NO_DEVICE_FOUND),
|
|
(asyncio.exceptions.CancelledError, ERROR_MSG_CANNOT_CONNECT),
|
|
(AddressInUseError, ERROR_MSG_ADDRESS_IN_USE),
|
|
],
|
|
)
|
|
async def test_devices_with_various_mocks_errors(
|
|
hass: HomeAssistant,
|
|
mock_start: AsyncMock,
|
|
mock_stop: AsyncMock,
|
|
mock_setup_entry: AsyncMock,
|
|
exception: Exception,
|
|
error_msg: str,
|
|
) -> None:
|
|
"""Test the various on error states - then finally complete the test."""
|
|
|
|
with patch(
|
|
"homeassistant.components.weatherflow.config_flow.WeatherFlowListener.on",
|
|
side_effect=exception,
|
|
):
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
assert result["type"] == FlowResultType.FORM
|
|
assert result["errors"]["base"] == error_msg
|
|
assert result["step_id"] == "user"
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
await hass.async_block_till_done()
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
assert result["data"] == {}
|