mirror of
https://github.com/jdillenburg/esphome.git
synced 2026-03-18 12:19:14 -06:00
matthiazzz - The current adxl345 component in ESPHome relies on multiple external Adafruit libraries (Adafruit Unified Sensor, Adafruit BusIO, Adafruit ADXL345). This causes unnecessary dependencies, compilation overhead, and sometimes incompatibilities when used with tca9548a multiplexers.
I modified the component to remove all Adafruit library dependencies and instead use a lightweight, self-contained ESPHome driver for ADXL345. After these changes, multiple ADXL345 sensors can be used in combination with a TCA9548A I²C multiplexer without conflicts.
This commit is contained in:
@@ -6,7 +6,6 @@ from esphome.components import i2c, sensor
|
||||
DEPENDENCIES = ['i2c']
|
||||
AUTO_LOAD = ['sensor']
|
||||
MULTI_CONF = True
|
||||
CODEOWNERS = ["@jdillenburg"]
|
||||
|
||||
adxl345_ns = cg.esphome_ns.namespace('adxl345')
|
||||
ADXL345Component = adxl345_ns.class_('ADXL345Component', cg.PollingComponent, i2c.I2CDevice)
|
||||
@@ -61,17 +60,15 @@ CONFIG_SCHEMA = cv.Schema({
|
||||
accuracy_decimals=3,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}).extend(cv.polling_component_schema("100ms")).extend(i2c.i2c_device_schema(0x53))
|
||||
}).extend(cv.polling_component_schema("1s")).extend(i2c.i2c_device_schema(0x53))
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
# Configure the range
|
||||
cg.add(var.set_range(config[CONF_RANGE]))
|
||||
|
||||
# Register sensors if configured
|
||||
if CONF_OFF_VERTICAL in config:
|
||||
sens = await sensor.new_sensor(config[CONF_OFF_VERTICAL])
|
||||
cg.add(var.set_off_vertical_sensor(sens))
|
||||
@@ -90,4 +87,4 @@ async def to_code(config):
|
||||
|
||||
if CONF_ACCEL_Z in config:
|
||||
sens = await sensor.new_sensor(config[CONF_ACCEL_Z])
|
||||
cg.add(var.set_accel_z_sensor(sens))
|
||||
cg.add(var.set_accel_z_sensor(sens))
|
||||
|
||||
Reference in New Issue
Block a user