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
a7fbac51
Unverified
Commit
a7fbac51
authored
8 months ago
by
dupondje
Committed by
GitHub
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
dsmr: migrate hourly_gas_meter_reading to mbus device (#123149)
parent
b45fe0ec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/dsmr/sensor.py
+3
-1
3 additions, 1 deletion
homeassistant/components/dsmr/sensor.py
tests/components/dsmr/test_mbus_migration.py
+100
-0
100 additions, 0 deletions
tests/components/dsmr/test_mbus_migration.py
with
103 additions
and
1 deletion
homeassistant/components/dsmr/sensor.py
+
3
−
1
View file @
a7fbac51
...
...
@@ -439,7 +439,9 @@ def rename_old_gas_to_mbus(
entries
=
er
.
async_entries_for_device
(
ent_reg
,
device_id
)
for
entity
in
entries
:
if
entity
.
unique_id
.
endswith
(
"
belgium_5min_gas_meter_reading
"
):
if
entity
.
unique_id
.
endswith
(
"
belgium_5min_gas_meter_reading
"
)
or
entity
.
unique_id
.
endswith
(
"
hourly_gas_meter_reading
"
):
try
:
ent_reg
.
async_update_entity
(
entity
.
entity_id
,
...
...
This diff is collapsed.
Click to expand it.
tests/components/dsmr/test_mbus_migration.py
+
100
−
0
View file @
a7fbac51
...
...
@@ -119,6 +119,106 @@ async def test_migrate_gas_to_mbus(
)
async
def
test_migrate_hourly_gas_to_mbus
(
hass
:
HomeAssistant
,
entity_registry
:
er
.
EntityRegistry
,
device_registry
:
dr
.
DeviceRegistry
,
dsmr_connection_fixture
:
tuple
[
MagicMock
,
MagicMock
,
MagicMock
],
)
->
None
:
"""
Test migration of unique_id.
"""
(
connection_factory
,
transport
,
protocol
)
=
dsmr_connection_fixture
mock_entry
=
MockConfigEntry
(
domain
=
DOMAIN
,
unique_id
=
"
/dev/ttyUSB0
"
,
data
=
{
"
port
"
:
"
/dev/ttyUSB0
"
,
"
dsmr_version
"
:
"
5
"
,
"
serial_id
"
:
"
1234
"
,
"
serial_id_gas
"
:
"
4730303738353635363037343639323231
"
,
},
options
=
{
"
time_between_update
"
:
0
,
},
)
mock_entry
.
add_to_hass
(
hass
)
old_unique_id
=
"
4730303738353635363037343639323231_hourly_gas_meter_reading
"
device
=
device_registry
.
async_get_or_create
(
config_entry_id
=
mock_entry
.
entry_id
,
identifiers
=
{(
DOMAIN
,
mock_entry
.
entry_id
)},
name
=
"
Gas Meter
"
,
)
await
hass
.
async_block_till_done
()
entity
:
er
.
RegistryEntry
=
entity_registry
.
async_get_or_create
(
suggested_object_id
=
"
gas_meter_reading
"
,
disabled_by
=
None
,
domain
=
SENSOR_DOMAIN
,
platform
=
DOMAIN
,
device_id
=
device
.
id
,
unique_id
=
old_unique_id
,
config_entry
=
mock_entry
,
)
assert
entity
.
unique_id
==
old_unique_id
await
hass
.
async_block_till_done
()
telegram
=
Telegram
()
telegram
.
add
(
MBUS_DEVICE_TYPE
,
CosemObject
((
0
,
1
),
[{
"
value
"
:
"
003
"
,
"
unit
"
:
""
}]),
"
MBUS_DEVICE_TYPE
"
,
)
telegram
.
add
(
MBUS_EQUIPMENT_IDENTIFIER
,
CosemObject
(
(
0
,
1
),
[{
"
value
"
:
"
4730303738353635363037343639323231
"
,
"
unit
"
:
""
}],
),
"
MBUS_EQUIPMENT_IDENTIFIER
"
,
)
telegram
.
add
(
MBUS_METER_READING
,
MBusObject
(
(
0
,
1
),
[
{
"
value
"
:
datetime
.
datetime
.
fromtimestamp
(
1722749707
)},
{
"
value
"
:
Decimal
(
778.963
),
"
unit
"
:
"
m3
"
},
],
),
"
MBUS_METER_READING
"
,
)
assert
await
hass
.
config_entries
.
async_setup
(
mock_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
telegram_callback
=
connection_factory
.
call_args_list
[
0
][
0
][
2
]
# simulate a telegram pushed from the smartmeter and parsed by dsmr_parser
telegram_callback
(
telegram
)
# after receiving telegram entities need to have the chance to be created
await
hass
.
async_block_till_done
()
dev_entities
=
er
.
async_entries_for_device
(
entity_registry
,
device
.
id
,
include_disabled_entities
=
True
)
assert
not
dev_entities
assert
(
entity_registry
.
async_get_entity_id
(
SENSOR_DOMAIN
,
DOMAIN
,
old_unique_id
)
is
None
)
assert
(
entity_registry
.
async_get_entity_id
(
SENSOR_DOMAIN
,
DOMAIN
,
"
4730303738353635363037343639323231
"
)
==
"
sensor.gas_meter_reading
"
)
async
def
test_migrate_gas_to_mbus_exists
(
hass
:
HomeAssistant
,
entity_registry
:
er
.
EntityRegistry
,
...
...
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