flyte / mqtt-io

Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.
MIT License
467 stars 158 forks source link

pcf8574 KeyError: <PinPUD.OFF: 1> #216

Closed IlmLV closed 3 years ago

IlmLV commented 3 years ago

Describe the bug Updated from v0.5.6 version to 2.2.6 and now I'm having error using pcf8574 module: KeyError: <PinPUD.OFF: 1> After little digging found that there is new default pud state PinPUD.OFF previously default state was None. In a result of that pcf8574 modules pullup_map lacks of this value map. I believe changing it to self.pullup_map = {PinPUD.OFF: None, PinPUD.UP: True, PinPUD.DOWN: False} would fix the issue.

Expected behavior Do not use pullup/pulldown if it is not necessary and run mqtt-io server without errors as it is supposed to be handled at this line.

Error messages and traceback

mqtt-io    | Traceback (most recent call last):
mqtt-io    |   File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
mqtt-io    |     return _run_code(code, main_globals, None,
mqtt-io    |   File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
mqtt-io    |     exec(code, run_globals)
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/__main__.py", line 85, in <module>
mqtt-io    |     main()
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/__main__.py", line 80, in main
mqtt-io    |     mqtt_gpio.run()
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 1168, in run
mqtt-io    |     self._init_digital_inputs()
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/server.py", line 386, in _init_digital_inputs
mqtt-io    |     gpio_module.setup_pin_internal(PinDirection.INPUT, in_conf)
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/modules/gpio/__init__.py", line 207, in setup_pin_internal
mqtt-io    |     return self.setup_pin(
mqtt-io    |   File "/home/mqttio/.local/lib/python3.9/site-packages/mqtt_io/modules/gpio/pcf8574.py", line 39, in setup_pin
mqtt-io    |     self.io.port[pin] = self.pullup_map[pullup]
mqtt-io    | KeyError: <PinPUD.OFF: 1>

Config

mqtt:
  [...]

gpio_modules:
  - name: pcf_1
    module: pcf8574
    i2c_bus_num: 1
    chip_addr: 0x22
    cleanup: False

digital_inputs:
  - name: master_bedroom_balcony_door
    module: pcf_1
    pin: 6
    on_payload: "OPEN"
    off_payload: "CLOSED"
    retain: yes

Hardware

System:

Additional context

IlmLV commented 3 years ago

also looks like using pcf8575 module would result in the same issue as pullup_map also has no mapping for PinPUD.OFF key