mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Fix pin reuse error with pin expanders (#5973)
Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
parent
d582cfa30a
commit
84174aeb80
3 changed files with 11 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
||||||
import operator
|
import operator
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.core import CORE, ID
|
from esphome.core import CORE
|
||||||
|
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_INPUT,
|
CONF_INPUT,
|
||||||
|
@ -25,15 +25,16 @@ class PinRegistry(dict):
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.pins_used = {}
|
self.pins_used = {}
|
||||||
|
|
||||||
def get_count(self, key, number):
|
def get_count(self, key, id, number):
|
||||||
"""
|
"""
|
||||||
Get the number of places a given pin is used.
|
Get the number of places a given pin is used.
|
||||||
:param key: The ID of the defining component
|
:param key: The key of the registered pin schema.
|
||||||
|
:param id: The ID of the defining component
|
||||||
:param number: The pin number
|
:param number: The pin number
|
||||||
:return: The number of places the pin is used.
|
:return: The number of places the pin is used.
|
||||||
"""
|
"""
|
||||||
pin_key = (key, number)
|
pin_key = (key, id, number)
|
||||||
return self.pins_used[pin_key] if pin_key in self.pins_used else 0
|
return len(self.pins_used[pin_key]) if pin_key in self.pins_used else 0
|
||||||
|
|
||||||
def register(self, name, schema, final_validate=None):
|
def register(self, name, schema, final_validate=None):
|
||||||
"""
|
"""
|
||||||
|
@ -65,9 +66,10 @@ class PinRegistry(dict):
|
||||||
result = self[key][1](conf)
|
result = self[key][1](conf)
|
||||||
if CONF_NUMBER in result:
|
if CONF_NUMBER in result:
|
||||||
# key maps to the pin schema
|
# key maps to the pin schema
|
||||||
if isinstance(key, ID):
|
if key != CORE.target_platform:
|
||||||
key = key.id
|
pin_key = (key, conf[key], result[CONF_NUMBER])
|
||||||
pin_key = (key, result[CONF_NUMBER])
|
else:
|
||||||
|
pin_key = (key, key, result[CONF_NUMBER])
|
||||||
if pin_key not in self.pins_used:
|
if pin_key not in self.pins_used:
|
||||||
self.pins_used[pin_key] = []
|
self.pins_used[pin_key] = []
|
||||||
# client_id identifies the instance of the providing component
|
# client_id identifies the instance of the providing component
|
||||||
|
@ -101,7 +103,7 @@ class PinRegistry(dict):
|
||||||
Run the final validation for all pins, and check for reuse
|
Run the final validation for all pins, and check for reuse
|
||||||
:param fconf: The full config
|
:param fconf: The full config
|
||||||
"""
|
"""
|
||||||
for (key, _), pin_list in self.pins_used.items():
|
for (key, _, _), pin_list in self.pins_used.items():
|
||||||
count = len(pin_list) # number of places same pin used.
|
count = len(pin_list) # number of places same pin used.
|
||||||
final_val_fun = self[key][2] # final validation function
|
final_val_fun = self[key][2] # final validation function
|
||||||
for pin_path, client_id, pin_config in pin_list:
|
for pin_path, client_id, pin_config in pin_list:
|
||||||
|
|
|
@ -1667,7 +1667,6 @@ binary_sensor:
|
||||||
mcp23xxx: mcp23s08_hub
|
mcp23xxx: mcp23s08_hub
|
||||||
# Use pin number 1
|
# Use pin number 1
|
||||||
number: 1
|
number: 1
|
||||||
allow_other_uses: true
|
|
||||||
# One of INPUT or INPUT_PULLUP
|
# One of INPUT or INPUT_PULLUP
|
||||||
mode: INPUT_PULLUP
|
mode: INPUT_PULLUP
|
||||||
inverted: false
|
inverted: false
|
||||||
|
@ -2149,7 +2148,6 @@ output:
|
||||||
pin:
|
pin:
|
||||||
mcp23xxx: mcp23017_hub
|
mcp23xxx: mcp23017_hub
|
||||||
number: 0
|
number: 0
|
||||||
allow_other_uses: true
|
|
||||||
mode: OUTPUT
|
mode: OUTPUT
|
||||||
inverted: false
|
inverted: false
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
@ -2157,7 +2155,6 @@ output:
|
||||||
pin:
|
pin:
|
||||||
mcp23xxx: mcp23008_hub
|
mcp23xxx: mcp23008_hub
|
||||||
number: 0
|
number: 0
|
||||||
allow_other_uses: true
|
|
||||||
mode: OUTPUT
|
mode: OUTPUT
|
||||||
inverted: false
|
inverted: false
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
@ -2597,7 +2594,6 @@ switch:
|
||||||
mcp23xxx: mcp23s08_hub
|
mcp23xxx: mcp23s08_hub
|
||||||
# Use pin number 0
|
# Use pin number 0
|
||||||
number: 0
|
number: 0
|
||||||
allow_other_uses: true
|
|
||||||
mode: OUTPUT
|
mode: OUTPUT
|
||||||
inverted: false
|
inverted: false
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
|
|
@ -401,7 +401,6 @@ switch:
|
||||||
pin:
|
pin:
|
||||||
mcp23xxx: mcp23017_hub
|
mcp23xxx: mcp23017_hub
|
||||||
number: 0
|
number: 0
|
||||||
allow_other_uses: true
|
|
||||||
mode: OUTPUT
|
mode: OUTPUT
|
||||||
interlock: &interlock [gpio_switch1, gpio_switch2, gpio_switch3]
|
interlock: &interlock [gpio_switch1, gpio_switch2, gpio_switch3]
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
@ -409,7 +408,6 @@ switch:
|
||||||
pin:
|
pin:
|
||||||
mcp23xxx: mcp23008_hub
|
mcp23xxx: mcp23008_hub
|
||||||
number: 0
|
number: 0
|
||||||
allow_other_uses: true
|
|
||||||
mode: OUTPUT
|
mode: OUTPUT
|
||||||
interlock: *interlock
|
interlock: *interlock
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
|
Loading…
Reference in a new issue