Skip to content

Commit

Permalink
Add exception for device_id with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Bloemberg committed Aug 25, 2020
1 parent 2874771 commit 18b19a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion rflink/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ def deserialize_packet_id(packet_id: str) -> Dict[str, str]:
if packet_id == "rflink":
return {"protocol": UNKNOWN}

protocol, *id_switch = packet_id.split(PACKET_ID_SEP)
if packet_id.startswith("dooya_v4"):
protocol = "dooya_v4"
id_switch = packet_id.replace("dooya_v4_", "").split(PACKET_ID_SEP)
else:
protocol, *id_switch = packet_id.split(PACKET_ID_SEP)

assert len(id_switch) < 3

packet_identifiers = {
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pylama]
linters = pydocstyle,pycodestyle,pyflakes,isort
linters = pydocstyle,pycodestyle,pyflakes
ignore = D213,E128,D203

[pycodestyle]
Expand Down
12 changes: 9 additions & 3 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def test_units():
@pytest.mark.parametrize(
"packet",
[
l.strip()
for l in open(PROTOCOL_SAMPLES).readlines()
if l.strip() and l[0] != "#"
line.strip()
for line in open(PROTOCOL_SAMPLES).readlines()
if line.strip() and line[0] != "#"
],
)
def test_packet_valiation(packet):
Expand All @@ -151,3 +151,9 @@ def test_invalid_type():
"id": "79",
"type": "10",
}


@pytest.mark.parametrize("device_id", ["dooya_v4_6d5f8e00_3f"])
def test_underscored(device_id):
"""Test parsing device id's that contain underscores."""
assert deserialize_packet_id(device_id)

1 comment on commit 18b19a8

@jgrob1
Copy link

@jgrob1 jgrob1 commented on 18b19a8 Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is marvellous- thank you. Forgive me though, I want to raise the PR but I am a complete Github noob. I think I need to find the parser.py file in home-assistant core repo but I cant. I cant get beyond the Compare Changes screen as I dont know the commit that I need to compare this one too. Are you able to advise on this? I also don't know how to tell the tests have been completed like you said in the closed issue.

Please sign in to comment.