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
85c72fbc
Commit
85c72fbc
authored
6 years ago
by
emontnemery
Committed by
Paulus Schoutsen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update device registry of MQTT alarm (#20439)
parent
85ccd71d
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
homeassistant/components/mqtt/alarm_control_panel.py
+6
-5
6 additions, 5 deletions
homeassistant/components/mqtt/alarm_control_panel.py
tests/components/mqtt/test_alarm_control_panel.py
+47
-0
47 additions, 0 deletions
tests/components/mqtt/test_alarm_control_panel.py
with
53 additions
and
5 deletions
homeassistant/components/mqtt/alarm_control_panel.py
+
6
−
5
View file @
85c72fbc
...
...
@@ -66,7 +66,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
try
:
discovery_hash
=
discovery_payload
[
ATTR_DISCOVERY_HASH
]
config
=
PLATFORM_SCHEMA
(
discovery_payload
)
await
_async_setup_entity
(
config
,
async_add_entities
,
await
_async_setup_entity
(
config
,
async_add_entities
,
config_entry
,
discovery_hash
)
except
Exception
:
if
discovery_hash
:
...
...
@@ -78,17 +78,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_discover
)
async
def
_async_setup_entity
(
config
,
async_add_entities
,
async
def
_async_setup_entity
(
config
,
async_add_entities
,
config_entry
=
None
,
discovery_hash
=
None
):
"""
Set up the MQTT Alarm Control Panel platform.
"""
async_add_entities
([
MqttAlarm
(
config
,
discovery_hash
)])
async_add_entities
([
MqttAlarm
(
config
,
config_entry
,
discovery_hash
)])
class
MqttAlarm
(
MqttAttributes
,
MqttAvailability
,
MqttDiscoveryUpdate
,
MqttEntityDeviceInfo
,
alarm
.
AlarmControlPanel
):
"""
Representation of a MQTT alarm status.
"""
def
__init__
(
self
,
config
,
discovery_hash
):
def
__init__
(
self
,
config
,
config_entry
,
discovery_hash
):
"""
Init the MQTT Alarm Control Panel.
"""
self
.
_state
=
None
self
.
_config
=
config
...
...
@@ -101,7 +101,7 @@ class MqttAlarm(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
MqttAvailability
.
__init__
(
self
,
config
)
MqttDiscoveryUpdate
.
__init__
(
self
,
discovery_hash
,
self
.
discovery_update
)
MqttEntityDeviceInfo
.
__init__
(
self
,
device_config
)
MqttEntityDeviceInfo
.
__init__
(
self
,
device_config
,
config_entry
)
async
def
async_added_to_hass
(
self
):
"""
Subscribe mqtt events.
"""
...
...
@@ -114,6 +114,7 @@ class MqttAlarm(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
self
.
_config
=
config
await
self
.
attributes_discovery_update
(
config
)
await
self
.
availability_discovery_update
(
config
)
await
self
.
device_info_discovery_update
(
config
)
await
self
.
_subscribe_topics
()
self
.
async_schedule_update_ha_state
()
...
...
This diff is collapsed.
Click to expand it.
tests/components/mqtt/test_alarm_control_panel.py
+
47
−
0
View file @
85c72fbc
...
...
@@ -515,6 +515,53 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
assert
device
.
sw_version
==
'
0.1-beta
'
async
def
test_entity_device_info_update
(
hass
,
mqtt_mock
):
"""
Test device registry update.
"""
entry
=
MockConfigEntry
(
domain
=
mqtt
.
DOMAIN
)
entry
.
add_to_hass
(
hass
)
await
async_start
(
hass
,
'
homeassistant
'
,
{},
entry
)
registry
=
await
hass
.
helpers
.
device_registry
.
async_get_registry
()
config
=
{
'
platform
'
:
'
mqtt
'
,
'
name
'
:
'
Test 1
'
,
'
state_topic
'
:
'
test-topic
'
,
'
command_topic
'
:
'
test-command-topic
'
,
'
device
'
:
{
'
identifiers
'
:
[
'
helloworld
'
],
'
connections
'
:
[
[
"
mac
"
,
"
02:5b:26:a8:dc:12
"
],
],
'
manufacturer
'
:
'
Whatever
'
,
'
name
'
:
'
Beer
'
,
'
model
'
:
'
Glass
'
,
'
sw_version
'
:
'
0.1-beta
'
,
},
'
unique_id
'
:
'
veryunique
'
}
data
=
json
.
dumps
(
config
)
async_fire_mqtt_message
(
hass
,
'
homeassistant/alarm_control_panel/bla/config
'
,
data
)
await
hass
.
async_block_till_done
()
await
hass
.
async_block_till_done
()
device
=
registry
.
async_get_device
({(
'
mqtt
'
,
'
helloworld
'
)},
set
())
assert
device
is
not
None
assert
device
.
name
==
'
Beer
'
config
[
'
device
'
][
'
name
'
]
=
'
Milk
'
data
=
json
.
dumps
(
config
)
async_fire_mqtt_message
(
hass
,
'
homeassistant/alarm_control_panel/bla/config
'
,
data
)
await
hass
.
async_block_till_done
()
await
hass
.
async_block_till_done
()
device
=
registry
.
async_get_device
({(
'
mqtt
'
,
'
helloworld
'
)},
set
())
assert
device
is
not
None
assert
device
.
name
==
'
Milk
'
async
def
test_entity_id_update
(
hass
,
mqtt_mock
):
"""
Test MQTT subscriptions are managed when entity_id is updated.
"""
registry
=
mock_registry
(
hass
,
{})
...
...
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