LarsMichelsen / pmatic

Python API for Homematic. Easy to use.
https://larsmichelsen.github.io/pmatic/
GNU General Public License v2.0
34 stars 23 forks source link

Store channels in dict to cater for gaps in indices #5

Closed jschmer closed 8 years ago

jschmer commented 8 years ago

Hi, first let me thank you for your nice work! I'm trying to contribute to this project with my HomeMatic setup. I'm working on Windows and tried to run the basic 'list all devices and channels with their values' scenario.

I found that some devices don't have continues channel numbers, for example the device HM-TC-IT-WM-W-EU: Kanaltyp Kanalnummer WEATHER_TRANSMIT 1 THERMALCONTROL_TRANSMIT 2 WINDOW_SWITCH_RECEIVER 3 REMOTECONTROL_RECEIVER 6 SWITCH_TRANSMIT 7

Channels 4-5 don't exist for this device. This is a problem because the code at https://github.com/LarsMichelsen/pmatic/blob/604f2736daeadf98930e1c8888cf09d1e967e2ad/pmatic/entities.py#L182 assumes that all channels have continues indices, e.g. channel index equals array index. Later on this will fail because when accessing the channel index 6 for this device it will fail because the array will contain only 5 channels.

Solution would be to store the channels in a dictionary with the channel numbers/index as key.

landscape-bot commented 8 years ago

Code Health Repository health decreased by 0.00% when pulling 7c8261a on jschmer:ChannelIndex into 604f273 on LarsMichelsen:master.

LarsMichelsen commented 8 years ago

Hi, thanks for your pull request. I applied it, but had to change it back to something more specific to keep the calling interface consistent. See my commit for details.