Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unique_id generation for AtwZoneSensors
The existing unique_id generation generated the same ids for both zones in 2 zone setups. This change adds a zone-<index> suffix to the id breaking existing 1 zone setups.
- Loading branch information
1 parent
3d45f00
commit 9e91b6f
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Test the MELCloud ATW zone sensor.""" | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from homeassistant.components.melcloud.sensor import AtwZoneSensor | ||
|
||
|
||
@pytest.fixture | ||
def mock_device(): | ||
"""Mock MELCloud device.""" | ||
with patch("homeassistant.components.melcloud.MelCloudDevice") as mock: | ||
mock.name = "name" | ||
mock.device.serial = 1234 | ||
mock.device.mac = "11:11:11:11:11:11" | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_zone_1(): | ||
"""Mock zone 1.""" | ||
with patch("pymelcloud.atw_device.Zone") as mock: | ||
mock.zone_index = 1 | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_zone_2(): | ||
"""Mock zone 2.""" | ||
with patch("pymelcloud.atw_device.Zone") as mock: | ||
mock.zone_index = 2 | ||
yield mock | ||
|
||
|
||
def test_zone_unique_ids(mock_device, mock_zone_1, mock_zone_2): | ||
"""Test unique id generation correctness.""" | ||
sensor_1 = AtwZoneSensor(mock_device, mock_zone_1, "room_temperature", {}) | ||
assert sensor_1.unique_id == "1234-11:11:11:11:11:11-room_temperature-zone-1" | ||
|
||
sensor_2 = AtwZoneSensor(mock_device, mock_zone_2, "room_temperature", {}) | ||
assert sensor_2.unique_id == "1234-11:11:11:11:11:11-room_temperature-zone-2" |