1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 07:45:56 +00:00

Add I2CMultiplexer in generel and the TCA9548A in special (#1410)

* Added I2CMultiplexer in generel and the TCA9548A in special

* cleanup

* tidy

* tidy

* tidy

* tidy

* Update CODEOWNERS

* Update CODEOWNERS

* added CODEOWNERS

* Fix CODEOWNERS

* protected function

* fixed scan

* fixed style

* added to test1.yaml

* Update esphome/components/tca9548a/__init__.py

* Update esphome/components/i2c/__init__.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/i2c/i2c.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/i2c/__init__.py

* Update esphome/components/i2c/__init__.py

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>

* Update esphome/components/i2c/i2c.cpp

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>

* added define statements for I2C Multiplexer

* fix

* try to tidy

* bug fix

* tidy

* override fix

* only change channel if different

* tidy

* added test

* testfix

* added defines

* tidy

* fix dep

* like recommended

Co-authored-by: Andreas Hergert <andreas.hergert@otrs.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
Andreas Hergert
2021-03-29 21:50:30 +02:00
committed by GitHub
parent ad76312f66
commit 9e23987db8
8 changed files with 178 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.const import (
CONF_CHANNEL,
CONF_FREQUENCY,
CONF_ID,
CONF_SCAN,
@@ -9,6 +10,7 @@ from esphome.const import (
CONF_SDA,
CONF_ADDRESS,
CONF_I2C_ID,
CONF_MULTIPLEXER,
)
from esphome.core import coroutine, coroutine_with_priority
@@ -16,6 +18,7 @@ CODEOWNERS = ["@esphome/core"]
i2c_ns = cg.esphome_ns.namespace("i2c")
I2CComponent = i2c_ns.class_("I2CComponent", cg.Component)
I2CDevice = i2c_ns.class_("I2CDevice")
I2CMultiplexer = i2c_ns.class_("I2CMultiplexer", I2CDevice)
MULTI_CONF = True
CONFIG_SCHEMA = cv.Schema(
@@ -30,6 +33,13 @@ CONFIG_SCHEMA = cv.Schema(
}
).extend(cv.COMPONENT_SCHEMA)
I2CMULTIPLEXER_SCHEMA = cv.Schema(
{
cv.Required(CONF_ID): cv.use_id(I2CMultiplexer),
cv.Required(CONF_CHANNEL): cv.uint8_t,
}
)
@coroutine_with_priority(1.0)
def to_code(config):
@@ -53,6 +63,7 @@ def i2c_device_schema(default_address):
"""
schema = {
cv.GenerateID(CONF_I2C_ID): cv.use_id(I2CComponent),
cv.Optional(CONF_MULTIPLEXER): I2CMULTIPLEXER_SCHEMA,
}
if default_address is None:
schema[cv.Required(CONF_ADDRESS)] = cv.i2c_address
@@ -72,3 +83,8 @@ def register_i2c_device(var, config):
parent = yield cg.get_variable(config[CONF_I2C_ID])
cg.add(var.set_i2c_parent(parent))
cg.add(var.set_i2c_address(config[CONF_ADDRESS]))
if CONF_MULTIPLEXER in config:
multiplexer = yield cg.get_variable(config[CONF_MULTIPLEXER][CONF_ID])
cg.add(
var.set_i2c_multiplexer(multiplexer, config[CONF_MULTIPLEXER][CONF_CHANNEL])
)