Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
14482ff6
Unverified
Commit
14482ff6
authored
6 months ago
by
mvn23
Committed by
GitHub
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Update opentherm_gw tests to prepare for new platforms (#125172)
Move MockConfigEntry to a fixture
parent
be8f1416
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/components/opentherm_gw/conftest.py
+21
-0
21 additions, 0 deletions
tests/components/opentherm_gw/conftest.py
tests/components/opentherm_gw/test_init.py
+18
-25
18 additions, 25 deletions
tests/components/opentherm_gw/test_init.py
with
39 additions
and
25 deletions
tests/components/opentherm_gw/conftest.py
+
21
−
0
View file @
14482ff6
...
...
@@ -6,8 +6,14 @@ from unittest.mock import AsyncMock, MagicMock, patch
from
pyotgw.vars
import
OTGW
,
OTGW_ABOUT
import
pytest
from
homeassistant.components.opentherm_gw
import
DOMAIN
from
homeassistant.const
import
CONF_DEVICE
,
CONF_ID
,
CONF_NAME
from
tests.common
import
MockConfigEntry
VERSION_TEST
=
"
4.2.5
"
MINIMAL_STATUS
=
{
OTGW
:
{
OTGW_ABOUT
:
f
"
OpenTherm Gateway
{
VERSION_TEST
}
"
}}
MOCK_GATEWAY_ID
=
"
mock_gateway
"
@pytest.fixture
...
...
@@ -39,3 +45,18 @@ def mock_pyotgw() -> Generator[MagicMock]:
),
):
yield
mock_gateway
@pytest.fixture
def
mock_config_entry
()
->
MockConfigEntry
:
"""
Mock an OpenTherm Gateway config entry.
"""
return
MockConfigEntry
(
domain
=
DOMAIN
,
title
=
"
Mock Gateway
"
,
data
=
{
CONF_NAME
:
"
Mock Gateway
"
,
CONF_DEVICE
:
"
/dev/null
"
,
CONF_ID
:
MOCK_GATEWAY_ID
,
},
options
=
{},
)
This diff is collapsed.
Click to expand it.
tests/components/opentherm_gw/test_init.py
+
18
−
25
View file @
14482ff6
...
...
@@ -8,38 +8,28 @@ from homeassistant.components.opentherm_gw.const import (
DOMAIN
,
OpenThermDeviceIdentifier
,
)
from
homeassistant.const
import
CONF_D
EVICE
,
CONF_ID
,
CONF_NAME
from
homeassistant.const
import
CONF_
I
D
from
homeassistant.core
import
HomeAssistant
from
homeassistant.helpers
import
device_registry
as
dr
,
entity_registry
as
er
from
.conftest
import
VERSION_TEST
from
.conftest
import
MOCK_GATEWAY_ID
,
VERSION_TEST
from
tests.common
import
MockConfigEntry
VERSION_NEW
=
"
4.2.8.1
"
MINIMAL_STATUS_UPD
=
{
OTGW
:
{
OTGW_ABOUT
:
f
"
OpenTherm Gateway
{
VERSION_NEW
}
"
}}
MOCK_GATEWAY_ID
=
"
mock_gateway
"
MOCK_CONFIG_ENTRY
=
MockConfigEntry
(
domain
=
DOMAIN
,
title
=
"
Mock Gateway
"
,
data
=
{
CONF_NAME
:
"
Mock Gateway
"
,
CONF_DEVICE
:
"
/dev/null
"
,
CONF_ID
:
MOCK_GATEWAY_ID
,
},
options
=
{},
)
async
def
test_device_registry_insert
(
hass
:
HomeAssistant
,
device_registry
:
dr
.
DeviceRegistry
,
mock_config_entry
:
MockConfigEntry
,
mock_pyotgw
:
MagicMock
,
)
->
None
:
"""
Test that the device registry is initialized correctly.
"""
MOCK_CONFIG_ENTRY
.
add_to_hass
(
hass
)
mock_config_entry
.
add_to_hass
(
hass
)
await
hass
.
config_entries
.
async_setup
(
MOCK_CONFIG_ENTRY
.
entry_id
)
await
hass
.
config_entries
.
async_setup
(
mock_config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
gw_dev
=
device_registry
.
async_get_device
(
...
...
@@ -52,13 +42,14 @@ async def test_device_registry_insert(
async
def
test_device_registry_update
(
hass
:
HomeAssistant
,
device_registry
:
dr
.
DeviceRegistry
,
mock_config_entry
:
MockConfigEntry
,
mock_pyotgw
:
MagicMock
,
)
->
None
:
"""
Test that the device registry is updated correctly.
"""
MOCK_CONFIG_ENTRY
.
add_to_hass
(
hass
)
mock_config_entry
.
add_to_hass
(
hass
)
device_registry
.
async_get_or_create
(
config_entry_id
=
MOCK_CONFIG_ENTRY
.
entry_id
,
config_entry_id
=
mock_config_entry
.
entry_id
,
identifiers
=
{
(
DOMAIN
,
f
"
{
MOCK_GATEWAY_ID
}
-
{
OpenThermDeviceIdentifier
.
GATEWAY
}
"
)
},
...
...
@@ -70,7 +61,7 @@ async def test_device_registry_update(
mock_pyotgw
.
return_value
.
connect
.
return_value
=
MINIMAL_STATUS_UPD
await
hass
.
config_entries
.
async_setup
(
MOCK_CONFIG_ENTRY
.
entry_id
)
await
hass
.
config_entries
.
async_setup
(
mock_config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
gw_dev
=
device_registry
.
async_get_device
(
...
...
@@ -84,13 +75,14 @@ async def test_device_registry_update(
async
def
test_device_migration
(
hass
:
HomeAssistant
,
device_registry
:
dr
.
DeviceRegistry
,
mock_config_entry
:
MockConfigEntry
,
mock_pyotgw
:
MagicMock
,
)
->
None
:
"""
Test that the device registry is updated correctly.
"""
MOCK_CONFIG_ENTRY
.
add_to_hass
(
hass
)
mock_config_entry
.
add_to_hass
(
hass
)
device_registry
.
async_get_or_create
(
config_entry_id
=
MOCK_CONFIG_ENTRY
.
entry_id
,
config_entry_id
=
mock_config_entry
.
entry_id
,
identifiers
=
{
(
DOMAIN
,
MOCK_GATEWAY_ID
),
},
...
...
@@ -100,7 +92,7 @@ async def test_device_migration(
sw_version
=
VERSION_TEST
,
)
await
hass
.
config_entries
.
async_setup
(
MOCK_CONFIG_ENTRY
.
entry_id
)
await
hass
.
config_entries
.
async_setup
(
mock_config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
assert
(
...
...
@@ -136,22 +128,23 @@ async def test_device_migration(
async
def
test_climate_entity_migration
(
hass
:
HomeAssistant
,
entity_registry
:
er
.
EntityRegistry
,
mock_config_entry
:
MockConfigEntry
,
mock_pyotgw
:
MagicMock
,
)
->
None
:
"""
Test that the climate entity unique_id gets migrated correctly.
"""
MOCK_CONFIG_ENTRY
.
add_to_hass
(
hass
)
mock_config_entry
.
add_to_hass
(
hass
)
entry
=
entity_registry
.
async_get_or_create
(
domain
=
"
climate
"
,
platform
=
"
opentherm_gw
"
,
unique_id
=
MOCK_CONFIG_ENTRY
.
data
[
CONF_ID
],
unique_id
=
mock_config_entry
.
data
[
CONF_ID
],
)
await
hass
.
config_entries
.
async_setup
(
MOCK_CONFIG_ENTRY
.
entry_id
)
await
hass
.
config_entries
.
async_setup
(
mock_config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
updated_entry
=
entity_registry
.
async_get
(
entry
.
entity_id
)
assert
updated_entry
is
not
None
assert
(
updated_entry
.
unique_id
==
f
"
{
MOCK_CONFIG_ENTRY
.
data
[
CONF_ID
]
}
-
{
OpenThermDeviceIdentifier
.
THERMOSTAT
}
-thermostat_entity
"
==
f
"
{
mock_config_entry
.
data
[
CONF_ID
]
}
-
{
OpenThermDeviceIdentifier
.
THERMOSTAT
}
-thermostat_entity
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment