Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Telegram.payload to support other APCI payloads #519

Merged
merged 22 commits into from
Dec 9, 2020

Conversation

basilfx
Copy link
Contributor

@basilfx basilfx commented Nov 30, 2020

Description

This is the second part of #253, where Telegram.payload is refactored to support generic APCI payloads. In addition, Telegram.telegramtype and CEMIFrame.cmd are obsolete as well, because they can be derived from the payload.

Most of the changes are related to the testcases, where Telegram(.., payload=DPT*()) is now (for example) Telegram(.., payload=GroupValueWrite(DPT*())).

I have not tested the Home-Assistant plugin, as I don't have a setup running. It probably needs some changes.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • The documentation has been adjusted accordingly
  • The changes generate no new warnings
  • Tests have been added that prove the fix is effective or that the feature works
  • The changes are documented in the changelog
  • The Homeassistant plugin has been adjusted in case of new config options

@basilfx
Copy link
Contributor Author

basilfx commented Nov 30, 2020

I have two MyPy errors left, which I don't understand:

xknx/telegram/apci.py:14: error: Module 'xknx.dpt' has no attribute 'DPTArray'; maybe "DPTArea"?
xknx/telegram/apci.py:14: error: Module 'xknx.dpt' has no attribute 'DPTBinary'

False positive?

@farmio
Copy link
Member

farmio commented Dec 1, 2020

Have you seen this: python/mypy#7423
Maybe we should adapt our Mypy config. I think from ... as ... would be odd.

@coveralls
Copy link

coveralls commented Dec 1, 2020

Coverage Status

Coverage increased (+0.09%) to 94.668% when pulling bf9fd22 on basilfx:feature/apci_payload into bcbd1a2 on XKNX:master.

@farmio
Copy link
Member

farmio commented Dec 1, 2020

when I run this now from my HA test installation I get a lot of

2020-12-01 22:12:26 WARNING (MainThread) [xknx.log] 'from_knx()' not implemented for GroupValueRead
# and this for GAs in fire_event_filter
2020-12-01 22:12:26 WARNING (Recorder) [homeassistant.components.recorder] Event is not JSON serializable: <Event knx_event[L]: data=<GroupValueResponse dpt="<DPTArray value="[0x19,0x62]" />" />, destination=5/1/0, direction=Incoming, source=1.0.54, telegramtype=GroupValueResponse>

also I think it would be cleaner if the APCI services could get their own module for importing them instead of importing from xknx.telegram together with higher-order classes

# eg
from xknx.telegram import GroupAddress, IndividualAddress, Telegram
from xknx.telegram.apci import GroupValueRead, GroupValueWrite
# instead of
from xknx.telegram import GroupAddress, GroupValueRead, GroupValueWrite, IndividualAddress, Telegram

@basilfx
Copy link
Contributor Author

basilfx commented Dec 1, 2020

@farmio Thanks for testing, I'll pick it up. I'm also busy with a few other improvements.

@basilfx
Copy link
Contributor Author

basilfx commented Dec 1, 2020

I'm still working on the APCI unit tests.

@basilfx
Copy link
Contributor Author

basilfx commented Dec 2, 2020

Unit tests are ready. Let's see what I have to add more :-)

@basilfx basilfx force-pushed the feature/apci_payload branch 4 times, most recently from 6445ed1 to b3196da Compare December 8, 2020 22:11
xknx/devices/device.py Outdated Show resolved Hide resolved
xknx/dpt/dpt.py Show resolved Hide resolved
xknx/telegram/apci.py Outdated Show resolved Hide resolved
@basilfx basilfx force-pushed the feature/apci_payload branch from 0e2c435 to 899b441 Compare December 8, 2020 22:53
This becomes unnecessary if the telegram type can be derrived from the
payload.
Thi adds payload classes that represent APCI messages, such as
GroupValueRead/Write/Response.
This adapts all Telegram payload objects to the corresponding APCI
payload objects. It removes the need for `Telegram.telegramtype`.
This can be derived from the payload of the telegram.
Byte 8 (mpdu_len) is the length of the APDU minus one. This can be
calculated from payload.calculated_length().
Unless a developer uses the TelegramQueue or Device class directly,
there doesn't seem to be a need for this check.
This removes the need for a constructor and false implementations of
the abstract methods.
Typing was necessary here for APCI code to be type checked.
@basilfx basilfx force-pushed the feature/apci_payload branch from 899b441 to df2fccd Compare December 8, 2020 23:16
xknx/knxip/cemi_frame.py Outdated Show resolved Hide resolved
@farmio farmio merged commit 8990e86 into XKNX:master Dec 9, 2020
@basilfx basilfx deleted the feature/apci_payload branch December 9, 2020 20:10
@basilfx
Copy link
Contributor Author

basilfx commented Dec 9, 2020

Thanks!

@farmio
Copy link
Member

farmio commented Dec 9, 2020

Thank you! I think its a great addition. 🙏

@basilfx basilfx mentioned this pull request Dec 16, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants