esphome 2024.9.1__py3-none-any.whl → 2024.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/components/aic3204/__init__.py +0 -0
- esphome/components/aic3204/aic3204.cpp +173 -0
- esphome/components/aic3204/aic3204.h +88 -0
- esphome/components/aic3204/audio_dac.py +52 -0
- esphome/components/aic3204/automation.h +23 -0
- esphome/components/alarm_control_panel/__init__.py +3 -4
- esphome/components/animation/__init__.py +16 -12
- esphome/components/api/api_connection.cpp +2 -0
- esphome/components/api/api_connection.h +3 -1
- esphome/components/api/api_frame_helper.cpp +2 -1
- esphome/components/api/api_frame_helper.h +2 -1
- esphome/components/api/api_server.cpp +2 -0
- esphome/components/api/api_server.h +3 -1
- esphome/components/api/custom_api_device.h +3 -2
- esphome/components/api/homeassistant_service.h +4 -3
- esphome/components/api/list_entities.cpp +2 -0
- esphome/components/api/list_entities.h +3 -2
- esphome/components/api/subscribe_state.cpp +2 -0
- esphome/components/api/subscribe_state.h +3 -2
- esphome/components/audio_dac/__init__.py +57 -0
- esphome/components/audio_dac/audio_dac.h +23 -0
- esphome/components/audio_dac/automation.h +43 -0
- esphome/components/bang_bang/bang_bang_climate.cpp +5 -2
- esphome/components/bedjet/bedjet_codec.cpp +4 -2
- esphome/components/binary_sensor/__init__.py +3 -4
- esphome/components/bl0906/sensor.py +3 -2
- esphome/components/button/__init__.py +3 -4
- esphome/components/ch422g/__init__.py +26 -17
- esphome/components/ch422g/ch422g.cpp +66 -49
- esphome/components/ch422g/ch422g.h +17 -19
- esphome/components/climate/__init__.py +3 -4
- esphome/components/cover/__init__.py +4 -5
- esphome/components/cse7766/cse7766.cpp +12 -1
- esphome/components/cse7766/cse7766.h +4 -0
- esphome/components/cse7766/sensor.py +13 -1
- esphome/components/cst816/touchscreen/__init__.py +7 -4
- esphome/components/cst816/touchscreen/cst816_touchscreen.cpp +20 -19
- esphome/components/cst816/touchscreen/cst816_touchscreen.h +2 -0
- esphome/components/datetime/__init__.py +21 -14
- esphome/components/datetime/datetime_base.h +8 -1
- esphome/components/datetime/datetime_entity.cpp +2 -0
- esphome/components/datetime/datetime_entity.h +2 -0
- esphome/components/datetime/time_entity.cpp +2 -0
- esphome/components/datetime/time_entity.h +2 -0
- esphome/components/esp32/__init__.py +20 -4
- esphome/components/esp32_improv/__init__.py +82 -1
- esphome/components/esp32_improv/automation.h +72 -0
- esphome/components/esp32_improv/esp32_improv_component.cpp +13 -5
- esphome/components/esp32_improv/esp32_improv_component.h +15 -0
- esphome/components/ethernet/__init__.py +5 -0
- esphome/components/ethernet/ethernet_component.cpp +13 -0
- esphome/components/ethernet/ethernet_component.h +1 -0
- esphome/components/event/__init__.py +20 -12
- esphome/components/fan/__init__.py +3 -4
- esphome/components/gp2y1010au0f/__init__.py +0 -0
- esphome/components/gp2y1010au0f/gp2y1010au0f.cpp +67 -0
- esphome/components/gp2y1010au0f/gp2y1010au0f.h +52 -0
- esphome/components/gp2y1010au0f/sensor.py +61 -0
- esphome/components/gpio_expander/__init__.py +0 -0
- esphome/components/gpio_expander/cached_gpio.h +38 -0
- esphome/components/grove_gas_mc_v2/__init__.py +0 -0
- esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp +88 -0
- esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h +39 -0
- esphome/components/grove_gas_mc_v2/sensor.py +77 -0
- esphome/components/haier/climate.py +4 -3
- esphome/components/haier/haier_base.cpp +63 -8
- esphome/components/haier/haier_base.h +29 -3
- esphome/components/haier/hon_climate.cpp +122 -65
- esphome/components/haier/hon_climate.h +18 -2
- esphome/components/haier/smartair2_climate.cpp +21 -21
- esphome/components/haier/switch/__init__.py +91 -0
- esphome/components/haier/switch/beeper.cpp +14 -0
- esphome/components/haier/switch/beeper.h +18 -0
- esphome/components/haier/switch/display.cpp +14 -0
- esphome/components/haier/switch/display.h +18 -0
- esphome/components/haier/switch/health_mode.cpp +14 -0
- esphome/components/haier/switch/health_mode.h +18 -0
- esphome/components/haier/switch/quiet_mode.cpp +14 -0
- esphome/components/haier/switch/quiet_mode.h +18 -0
- esphome/components/hmac_md5/hmac_md5.cpp +2 -0
- esphome/components/hmac_md5/hmac_md5.h +2 -1
- esphome/components/i2s_audio/speaker/__init__.py +19 -0
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +1 -1
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +2 -0
- esphome/components/ili9xxx/ili9xxx_display.h +1 -0
- esphome/components/image/__init__.py +12 -12
- esphome/components/image/image.cpp +44 -0
- esphome/components/image/image.h +17 -2
- esphome/components/inkplate6/display.py +2 -0
- esphome/components/inkplate6/inkplate.h +30 -2
- esphome/components/light/__init__.py +3 -4
- esphome/components/lock/__init__.py +3 -4
- esphome/components/lvgl/__init__.py +16 -5
- esphome/components/lvgl/defines.py +1 -0
- esphome/components/lvgl/hello_world.py +64 -0
- esphome/components/lvgl/lv_validation.py +159 -3
- esphome/components/lvgl/lvgl_esphome.cpp +0 -43
- esphome/components/lvgl/lvgl_esphome.h +0 -4
- esphome/components/lvgl/styles.py +3 -2
- esphome/components/lvgl/text/__init__.py +3 -3
- esphome/components/lvgl/widgets/__init__.py +2 -0
- esphome/components/lvgl/widgets/animimg.py +3 -4
- esphome/components/lvgl/widgets/dropdown.py +5 -1
- esphome/components/lvgl/widgets/meter.py +16 -11
- esphome/components/md5/__init__.py +6 -0
- esphome/components/md5/md5.cpp +2 -0
- esphome/components/md5/md5.h +2 -0
- esphome/components/micro_wake_word/__init__.py +7 -0
- esphome/components/mics_4514/sensor.py +11 -26
- esphome/components/modbus_controller/__init__.py +7 -5
- esphome/components/modbus_controller/binary_sensor/__init__.py +6 -6
- esphome/components/modbus_controller/number/__init__.py +5 -6
- esphome/components/modbus_controller/output/__init__.py +10 -14
- esphome/components/modbus_controller/select/__init__.py +1 -1
- esphome/components/modbus_controller/sensor/__init__.py +7 -7
- esphome/components/modbus_controller/switch/__init__.py +6 -7
- esphome/components/modbus_controller/text_sensor/__init__.py +8 -9
- esphome/components/mqtt/__init__.py +3 -0
- esphome/components/mqtt/mqtt_client.cpp +2 -0
- esphome/components/mqtt/mqtt_client.h +2 -0
- esphome/components/nau7802/__init__.py +0 -0
- esphome/components/nau7802/nau7802.cpp +323 -0
- esphome/components/nau7802/nau7802.h +121 -0
- esphome/components/nau7802/sensor.py +134 -0
- esphome/components/nextion/base_component.py +1 -0
- esphome/components/nextion/display.py +4 -0
- esphome/components/nextion/nextion.cpp +19 -4
- esphome/components/nextion/nextion.h +16 -0
- esphome/components/npi19/__init__.py +0 -0
- esphome/components/npi19/npi19.cpp +111 -0
- esphome/components/npi19/npi19.h +30 -0
- esphome/components/npi19/sensor.py +52 -0
- esphome/components/number/__init__.py +3 -5
- esphome/components/online_image/__init__.py +1 -1
- esphome/components/online_image/online_image.h +1 -2
- esphome/components/opentherm/__init__.py +57 -0
- esphome/components/opentherm/hub.cpp +277 -0
- esphome/components/opentherm/hub.h +110 -0
- esphome/components/opentherm/opentherm.cpp +568 -0
- esphome/components/opentherm/opentherm.h +347 -0
- esphome/components/pulse_counter/pulse_counter_sensor.cpp +8 -1
- esphome/components/pulse_counter/pulse_counter_sensor.h +1 -0
- esphome/components/radon_eye_ble/radon_eye_listener.cpp +10 -3
- esphome/components/remote_transmitter/__init__.py +18 -2
- esphome/components/remote_transmitter/remote_transmitter.h +6 -0
- esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +2 -0
- esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +2 -0
- esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +2 -0
- esphome/components/rp2040/__init__.py +13 -14
- esphome/components/select/__init__.py +3 -4
- esphome/components/sensor/__init__.py +3 -4
- esphome/components/shelly_dimmer/shelly_dimmer.cpp +32 -32
- esphome/components/shelly_dimmer/shelly_dimmer.h +2 -0
- esphome/components/st7701s/st7701s.cpp +21 -8
- esphome/components/st7701s/st7701s.h +2 -0
- esphome/components/switch/__init__.py +3 -4
- esphome/components/tca9555/__init__.py +72 -0
- esphome/components/tca9555/tca9555.cpp +140 -0
- esphome/components/tca9555/tca9555.h +64 -0
- esphome/components/tcs34725/tcs34725.cpp +62 -64
- esphome/components/tem3200/__init__.py +0 -0
- esphome/components/tem3200/sensor.py +55 -0
- esphome/components/tem3200/tem3200.cpp +151 -0
- esphome/components/tem3200/tem3200.h +30 -0
- esphome/components/template/binary_sensor/__init__.py +19 -6
- esphome/components/text/__init__.py +3 -4
- esphome/components/text_sensor/__init__.py +3 -4
- esphome/components/thermostat/climate.py +11 -9
- esphome/components/thermostat/thermostat_climate.cpp +21 -15
- esphome/components/tm1638/binary_sensor/__init__.py +3 -2
- esphome/components/tm1638/display.py +5 -5
- esphome/components/tm1638/output/__init__.py +3 -2
- esphome/components/tm1638/switch/__init__.py +3 -2
- esphome/components/touchscreen/touchscreen.cpp +2 -2
- esphome/components/update/__init__.py +3 -4
- esphome/components/valve/__init__.py +3 -4
- esphome/components/web_server/__init__.py +78 -22
- esphome/components/web_server/server_index_v3.h +3989 -3979
- esphome/components/web_server/web_server.cpp +219 -34
- esphome/components/web_server/web_server.h +10 -1
- esphome/components/wifi/wifi_component_esp_idf.cpp +4 -5
- esphome/config_validation.py +1 -0
- esphome/const.py +12 -2
- esphome/core/defines.h +4 -2
- esphome/core/helpers.cpp +46 -10
- esphome/core/helpers.h +8 -0
- esphome/core/ring_buffer.cpp +12 -2
- esphome/core/ring_buffer.h +3 -0
- esphome/voluptuous_schema.py +3 -1
- esphome/wizard.py +0 -3
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/METADATA +5 -3
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/RECORD +196 -147
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/LICENSE +0 -0
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/WHEEL +0 -0
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/entry_points.txt +0 -0
- {esphome-2024.9.1.dist-info → esphome-2024.10.0.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,14 @@
|
|
1
1
|
import esphome.codegen as cg
|
2
|
+
from esphome.components import i2c, sensor
|
2
3
|
import esphome.config_validation as cv
|
3
|
-
|
4
|
-
from esphome.components import sensor, i2c
|
5
|
-
|
6
4
|
from esphome.const import (
|
5
|
+
CONF_AMMONIA,
|
6
|
+
CONF_CARBON_MONOXIDE,
|
7
|
+
CONF_ETHANOL,
|
8
|
+
CONF_HYDROGEN,
|
7
9
|
CONF_ID,
|
10
|
+
CONF_METHANE,
|
11
|
+
CONF_NITROGEN_DIOXIDE,
|
8
12
|
STATE_CLASS_MEASUREMENT,
|
9
13
|
UNIT_PARTS_PER_MILLION,
|
10
14
|
)
|
@@ -12,13 +16,6 @@ from esphome.const import (
|
|
12
16
|
CODEOWNERS = ["@jesserockz"]
|
13
17
|
DEPENDENCIES = ["i2c"]
|
14
18
|
|
15
|
-
CONF_CARBON_MONOXIDE = "carbon_monoxide"
|
16
|
-
CONF_NITROGEN_DIOXIDE = "nitrogen_dioxide"
|
17
|
-
CONF_METHANE = "methane"
|
18
|
-
CONF_ETHANOL = "ethanol"
|
19
|
-
CONF_HYDROGEN = "hydrogen"
|
20
|
-
CONF_AMMONIA = "ammonia"
|
21
|
-
|
22
19
|
|
23
20
|
mics_4514_ns = cg.esphome_ns.namespace("mics_4514")
|
24
21
|
MICS4514Component = mics_4514_ns.class_(
|
@@ -31,6 +28,7 @@ SENSORS = [
|
|
31
28
|
CONF_ETHANOL,
|
32
29
|
CONF_HYDROGEN,
|
33
30
|
CONF_AMMONIA,
|
31
|
+
CONF_NITROGEN_DIOXIDE,
|
34
32
|
]
|
35
33
|
|
36
34
|
common_sensor_schema = sensor.sensor_schema(
|
@@ -40,16 +38,7 @@ common_sensor_schema = sensor.sensor_schema(
|
|
40
38
|
)
|
41
39
|
|
42
40
|
CONFIG_SCHEMA = (
|
43
|
-
cv.Schema(
|
44
|
-
{
|
45
|
-
cv.GenerateID(): cv.declare_id(MICS4514Component),
|
46
|
-
cv.Optional(CONF_NITROGEN_DIOXIDE): sensor.sensor_schema(
|
47
|
-
unit_of_measurement=UNIT_PARTS_PER_MILLION,
|
48
|
-
state_class=STATE_CLASS_MEASUREMENT,
|
49
|
-
accuracy_decimals=2,
|
50
|
-
),
|
51
|
-
}
|
52
|
-
)
|
41
|
+
cv.Schema({cv.GenerateID(): cv.declare_id(MICS4514Component)})
|
53
42
|
.extend({cv.Optional(sensor_type): common_sensor_schema for sensor_type in SENSORS})
|
54
43
|
.extend(i2c.i2c_device_schema(0x75))
|
55
44
|
.extend(cv.polling_component_schema("60s"))
|
@@ -62,10 +51,6 @@ async def to_code(config):
|
|
62
51
|
await i2c.register_i2c_device(var, config)
|
63
52
|
|
64
53
|
for sensor_type in SENSORS:
|
65
|
-
if
|
66
|
-
sens = await sensor.new_sensor(
|
54
|
+
if sensor_config := config.get(sensor_type):
|
55
|
+
sens = await sensor.new_sensor(sensor_config)
|
67
56
|
cg.add(getattr(var, f"set_{sensor_type}_sensor")(sens))
|
68
|
-
|
69
|
-
if CONF_NITROGEN_DIOXIDE in config:
|
70
|
-
sens = await sensor.new_sensor(config[CONF_NITROGEN_DIOXIDE])
|
71
|
-
cg.add(var.set_nitrogen_dioxide_sensor(sens))
|
@@ -1,27 +1,29 @@
|
|
1
1
|
import binascii
|
2
|
-
|
3
|
-
import esphome.config_validation as cv
|
2
|
+
|
4
3
|
from esphome import automation
|
4
|
+
import esphome.codegen as cg
|
5
5
|
from esphome.components import modbus
|
6
|
+
import esphome.config_validation as cv
|
6
7
|
from esphome.const import (
|
7
8
|
CONF_ADDRESS,
|
8
9
|
CONF_ID,
|
9
|
-
CONF_NAME,
|
10
10
|
CONF_LAMBDA,
|
11
|
+
CONF_NAME,
|
11
12
|
CONF_OFFSET,
|
12
13
|
CONF_TRIGGER_ID,
|
13
14
|
)
|
14
15
|
from esphome.cpp_helpers import logging
|
16
|
+
|
15
17
|
from .const import (
|
16
18
|
CONF_ALLOW_DUPLICATE_COMMANDS,
|
17
19
|
CONF_BITMASK,
|
18
20
|
CONF_BYTE_OFFSET,
|
19
21
|
CONF_COMMAND_THROTTLE,
|
20
|
-
CONF_OFFLINE_SKIP_UPDATES,
|
21
22
|
CONF_CUSTOM_COMMAND,
|
22
23
|
CONF_FORCE_NEW_RANGE,
|
23
|
-
CONF_MODBUS_CONTROLLER_ID,
|
24
24
|
CONF_MAX_CMD_RETRIES,
|
25
|
+
CONF_MODBUS_CONTROLLER_ID,
|
26
|
+
CONF_OFFLINE_SKIP_UPDATES,
|
25
27
|
CONF_ON_COMMAND_SENT,
|
26
28
|
CONF_REGISTER_COUNT,
|
27
29
|
CONF_REGISTER_TYPE,
|
@@ -1,16 +1,16 @@
|
|
1
|
+
import esphome.codegen as cg
|
1
2
|
from esphome.components import binary_sensor
|
2
3
|
import esphome.config_validation as cv
|
3
|
-
import esphome.codegen as cg
|
4
|
-
|
5
4
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
5
|
+
|
6
6
|
from .. import (
|
7
|
+
MODBUS_REGISTER_TYPE,
|
8
|
+
ModbusItemBaseSchema,
|
9
|
+
SensorItem,
|
7
10
|
add_modbus_base_properties,
|
8
|
-
modbus_controller_ns,
|
9
11
|
modbus_calc_properties,
|
12
|
+
modbus_controller_ns,
|
10
13
|
validate_modbus_register,
|
11
|
-
ModbusItemBaseSchema,
|
12
|
-
SensorItem,
|
13
|
-
MODBUS_REGISTER_TYPE,
|
14
14
|
)
|
15
15
|
from ..const import (
|
16
16
|
CONF_BITMASK,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import esphome.codegen as cg
|
2
|
-
import esphome.config_validation as cv
|
3
2
|
from esphome.components import number
|
3
|
+
import esphome.config_validation as cv
|
4
4
|
from esphome.const import (
|
5
5
|
CONF_ADDRESS,
|
6
6
|
CONF_ID,
|
@@ -12,14 +12,13 @@ from esphome.const import (
|
|
12
12
|
|
13
13
|
from .. import (
|
14
14
|
MODBUS_WRITE_REGISTER_TYPE,
|
15
|
-
|
16
|
-
modbus_controller_ns,
|
17
|
-
modbus_calc_properties,
|
15
|
+
SENSOR_VALUE_TYPE,
|
18
16
|
ModbusItemBaseSchema,
|
19
17
|
SensorItem,
|
20
|
-
|
18
|
+
add_modbus_base_properties,
|
19
|
+
modbus_calc_properties,
|
20
|
+
modbus_controller_ns,
|
21
21
|
)
|
22
|
-
|
23
22
|
from ..const import (
|
24
23
|
CONF_BITMASK,
|
25
24
|
CONF_CUSTOM_COMMAND,
|
@@ -1,20 +1,15 @@
|
|
1
1
|
import esphome.codegen as cg
|
2
|
-
import esphome.config_validation as cv
|
3
2
|
from esphome.components import output
|
4
|
-
|
5
|
-
|
6
|
-
CONF_ID,
|
7
|
-
CONF_MULTIPLY,
|
8
|
-
)
|
3
|
+
import esphome.config_validation as cv
|
4
|
+
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_MULTIPLY
|
9
5
|
|
10
6
|
from .. import (
|
11
|
-
|
12
|
-
modbus_calc_properties,
|
7
|
+
SENSOR_VALUE_TYPE,
|
13
8
|
ModbusItemBaseSchema,
|
14
9
|
SensorItem,
|
15
|
-
|
10
|
+
modbus_calc_properties,
|
11
|
+
modbus_controller_ns,
|
16
12
|
)
|
17
|
-
|
18
13
|
from ..const import (
|
19
14
|
CONF_MODBUS_CONTROLLER_ID,
|
20
15
|
CONF_REGISTER_TYPE,
|
@@ -65,6 +60,7 @@ CONFIG_SCHEMA = cv.typed_schema(
|
|
65
60
|
async def to_code(config):
|
66
61
|
byte_offset, reg_count = modbus_calc_properties(config)
|
67
62
|
# Binary Output
|
63
|
+
write_template = None
|
68
64
|
if config[CONF_REGISTER_TYPE] == "coil":
|
69
65
|
var = cg.new_Pvariable(
|
70
66
|
config[CONF_ID],
|
@@ -72,7 +68,7 @@ async def to_code(config):
|
|
72
68
|
byte_offset,
|
73
69
|
)
|
74
70
|
if CONF_WRITE_LAMBDA in config:
|
75
|
-
|
71
|
+
write_template = await cg.process_lambda(
|
76
72
|
config[CONF_WRITE_LAMBDA],
|
77
73
|
[
|
78
74
|
(ModbusBinaryOutput.operator("ptr"), "item"),
|
@@ -92,7 +88,7 @@ async def to_code(config):
|
|
92
88
|
)
|
93
89
|
cg.add(var.set_write_multiply(config[CONF_MULTIPLY]))
|
94
90
|
if CONF_WRITE_LAMBDA in config:
|
95
|
-
|
91
|
+
write_template = await cg.process_lambda(
|
96
92
|
config[CONF_WRITE_LAMBDA],
|
97
93
|
[
|
98
94
|
(ModbusFloatOutput.operator("ptr"), "item"),
|
@@ -105,5 +101,5 @@ async def to_code(config):
|
|
105
101
|
parent = await cg.get_variable(config[CONF_MODBUS_CONTROLLER_ID])
|
106
102
|
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
|
107
103
|
cg.add(var.set_parent(parent))
|
108
|
-
if
|
109
|
-
cg.add(var.set_write_template(
|
104
|
+
if write_template:
|
105
|
+
cg.add(var.set_write_template(write_template))
|
@@ -1,17 +1,17 @@
|
|
1
|
+
import esphome.codegen as cg
|
1
2
|
from esphome.components import sensor
|
2
3
|
import esphome.config_validation as cv
|
3
|
-
|
4
|
+
from esphome.const import CONF_ADDRESS, CONF_ID
|
4
5
|
|
5
|
-
from esphome.const import CONF_ID, CONF_ADDRESS
|
6
6
|
from .. import (
|
7
|
+
MODBUS_REGISTER_TYPE,
|
8
|
+
SENSOR_VALUE_TYPE,
|
9
|
+
ModbusItemBaseSchema,
|
10
|
+
SensorItem,
|
7
11
|
add_modbus_base_properties,
|
8
|
-
modbus_controller_ns,
|
9
12
|
modbus_calc_properties,
|
13
|
+
modbus_controller_ns,
|
10
14
|
validate_modbus_register,
|
11
|
-
ModbusItemBaseSchema,
|
12
|
-
SensorItem,
|
13
|
-
MODBUS_REGISTER_TYPE,
|
14
|
-
SENSOR_VALUE_TYPE,
|
15
15
|
)
|
16
16
|
from ..const import (
|
17
17
|
CONF_BITMASK,
|
@@ -1,17 +1,16 @@
|
|
1
|
+
import esphome.codegen as cg
|
1
2
|
from esphome.components import switch
|
2
3
|
import esphome.config_validation as cv
|
3
|
-
|
4
|
-
|
4
|
+
from esphome.const import CONF_ADDRESS, CONF_ID
|
5
5
|
|
6
|
-
from esphome.const import CONF_ID, CONF_ADDRESS
|
7
6
|
from .. import (
|
7
|
+
MODBUS_REGISTER_TYPE,
|
8
|
+
ModbusItemBaseSchema,
|
9
|
+
SensorItem,
|
8
10
|
add_modbus_base_properties,
|
9
|
-
modbus_controller_ns,
|
10
11
|
modbus_calc_properties,
|
12
|
+
modbus_controller_ns,
|
11
13
|
validate_modbus_register,
|
12
|
-
ModbusItemBaseSchema,
|
13
|
-
SensorItem,
|
14
|
-
MODBUS_REGISTER_TYPE,
|
15
14
|
)
|
16
15
|
from ..const import (
|
17
16
|
CONF_BITMASK,
|
@@ -1,26 +1,25 @@
|
|
1
|
+
import esphome.codegen as cg
|
1
2
|
from esphome.components import text_sensor
|
2
3
|
import esphome.config_validation as cv
|
3
|
-
import esphome.codegen as cg
|
4
|
-
|
5
|
-
|
6
4
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
5
|
+
|
7
6
|
from .. import (
|
7
|
+
MODBUS_REGISTER_TYPE,
|
8
|
+
ModbusItemBaseSchema,
|
9
|
+
SensorItem,
|
8
10
|
add_modbus_base_properties,
|
9
|
-
modbus_controller_ns,
|
10
11
|
modbus_calc_properties,
|
12
|
+
modbus_controller_ns,
|
11
13
|
validate_modbus_register,
|
12
|
-
ModbusItemBaseSchema,
|
13
|
-
SensorItem,
|
14
|
-
MODBUS_REGISTER_TYPE,
|
15
14
|
)
|
16
15
|
from ..const import (
|
17
16
|
CONF_FORCE_NEW_RANGE,
|
18
17
|
CONF_MODBUS_CONTROLLER_ID,
|
18
|
+
CONF_RAW_ENCODE,
|
19
19
|
CONF_REGISTER_COUNT,
|
20
|
+
CONF_REGISTER_TYPE,
|
20
21
|
CONF_RESPONSE_SIZE,
|
21
22
|
CONF_SKIP_UPDATES,
|
22
|
-
CONF_RAW_ENCODE,
|
23
|
-
CONF_REGISTER_TYPE,
|
24
23
|
)
|
25
24
|
|
26
25
|
DEPENDENCIES = ["modbus_controller"]
|
@@ -11,6 +11,7 @@ from esphome.const import (
|
|
11
11
|
CONF_BIRTH_MESSAGE,
|
12
12
|
CONF_BROKER,
|
13
13
|
CONF_CERTIFICATE_AUTHORITY,
|
14
|
+
CONF_CLEAN_SESSION,
|
14
15
|
CONF_CLIENT_CERTIFICATE,
|
15
16
|
CONF_CLIENT_CERTIFICATE_KEY,
|
16
17
|
CONF_CLIENT_ID,
|
@@ -209,6 +210,7 @@ CONFIG_SCHEMA = cv.All(
|
|
209
210
|
cv.Optional(CONF_PORT, default=1883): cv.port,
|
210
211
|
cv.Optional(CONF_USERNAME, default=""): cv.string,
|
211
212
|
cv.Optional(CONF_PASSWORD, default=""): cv.string,
|
213
|
+
cv.Optional(CONF_CLEAN_SESSION, default=False): cv.boolean,
|
212
214
|
cv.Optional(CONF_CLIENT_ID): cv.string,
|
213
215
|
cv.SplitDefault(CONF_IDF_SEND_ASYNC, esp32_idf=False): cv.All(
|
214
216
|
cv.boolean, cv.only_with_esp_idf
|
@@ -325,6 +327,7 @@ async def to_code(config):
|
|
325
327
|
cg.add(var.set_broker_port(config[CONF_PORT]))
|
326
328
|
cg.add(var.set_username(config[CONF_USERNAME]))
|
327
329
|
cg.add(var.set_password(config[CONF_PASSWORD]))
|
330
|
+
cg.add(var.set_clean_session(config[CONF_CLEAN_SESSION]))
|
328
331
|
if CONF_CLIENT_ID in config:
|
329
332
|
cg.add(var.set_client_id(config[CONF_CLIENT_ID]))
|
330
333
|
|
@@ -147,6 +147,7 @@ void MQTTClientComponent::dump_config() {
|
|
147
147
|
this->ip_.str().c_str());
|
148
148
|
ESP_LOGCONFIG(TAG, " Username: " LOG_SECRET("'%s'"), this->credentials_.username.c_str());
|
149
149
|
ESP_LOGCONFIG(TAG, " Client ID: " LOG_SECRET("'%s'"), this->credentials_.client_id.c_str());
|
150
|
+
ESP_LOGCONFIG(TAG, " Clean Session: %s", YESNO(this->credentials_.clean_session));
|
150
151
|
if (this->is_discovery_ip_enabled()) {
|
151
152
|
ESP_LOGCONFIG(TAG, " Discovery IP enabled");
|
152
153
|
}
|
@@ -246,6 +247,7 @@ void MQTTClientComponent::start_connect_() {
|
|
246
247
|
this->mqtt_backend_.disconnect();
|
247
248
|
|
248
249
|
this->mqtt_backend_.set_client_id(this->credentials_.client_id.c_str());
|
250
|
+
this->mqtt_backend_.set_clean_session(this->credentials_.clean_session);
|
249
251
|
const char *username = nullptr;
|
250
252
|
if (!this->credentials_.username.empty())
|
251
253
|
username = this->credentials_.username.c_str();
|
@@ -51,6 +51,7 @@ struct MQTTCredentials {
|
|
51
51
|
std::string username;
|
52
52
|
std::string password;
|
53
53
|
std::string client_id; ///< The client ID. Will automatically be truncated to 23 characters.
|
54
|
+
bool clean_session; ///< Whether the session will be cleaned or remembered between connects.
|
54
55
|
};
|
55
56
|
|
56
57
|
/// Simple data struct for Home Assistant component availability.
|
@@ -254,6 +255,7 @@ class MQTTClientComponent : public Component {
|
|
254
255
|
void set_username(const std::string &username) { this->credentials_.username = username; }
|
255
256
|
void set_password(const std::string &password) { this->credentials_.password = password; }
|
256
257
|
void set_client_id(const std::string &client_id) { this->credentials_.client_id = client_id; }
|
258
|
+
void set_clean_session(const bool &clean_session) { this->credentials_.clean_session = clean_session; }
|
257
259
|
void set_on_connect(mqtt_on_connect_callback_t &&callback);
|
258
260
|
void set_on_disconnect(mqtt_on_disconnect_callback_t &&callback);
|
259
261
|
|
File without changes
|
@@ -0,0 +1,323 @@
|
|
1
|
+
#include "nau7802.h"
|
2
|
+
#include "esphome/core/log.h"
|
3
|
+
#include "esphome/core/hal.h"
|
4
|
+
|
5
|
+
namespace esphome {
|
6
|
+
namespace nau7802 {
|
7
|
+
|
8
|
+
static const char *const TAG = "nau7802";
|
9
|
+
|
10
|
+
// Only define what we need
|
11
|
+
|
12
|
+
static const uint8_t READ_BIT = 0x01;
|
13
|
+
|
14
|
+
static const uint8_t PU_CTRL_REG = 0x00;
|
15
|
+
static const uint8_t PU_CTRL_REGISTER_RESET = 0x01;
|
16
|
+
static const uint8_t PU_CTRL_POWERUP_DIGITAL = 0x02;
|
17
|
+
static const uint8_t PU_CTRL_POWERUP_ANALOG = 0x04;
|
18
|
+
static const uint8_t PU_CTRL_POWERUP_READY = 0x08;
|
19
|
+
static const uint8_t PU_CTRL_CYCLE_START = 0x10;
|
20
|
+
static const uint8_t PU_CTRL_CYCLE_READY = 0x20;
|
21
|
+
static const uint8_t PU_CTRL_AVDD_EXTERNAL = 0x80;
|
22
|
+
|
23
|
+
static const uint8_t CTRL1_REG = 0x01;
|
24
|
+
static const uint8_t CTRL1_LDO_SHIFT = 3;
|
25
|
+
static const uint8_t CTRL1_LDO_MASK = (0x7 << CTRL1_LDO_SHIFT);
|
26
|
+
static const uint8_t CTRL1_GAIN_MASK = 0x7;
|
27
|
+
|
28
|
+
static const uint8_t CTRL2_REG = 0x02;
|
29
|
+
static const uint8_t CTRL2_CRS_SHIFT = 4;
|
30
|
+
static const uint8_t CTRL2_CRS_MASK = (0x7 << CTRL2_CRS_SHIFT);
|
31
|
+
static const uint8_t CTRL2_CALS = 0x04;
|
32
|
+
static const uint8_t CTRL2_CAL_ERR = 0x08;
|
33
|
+
static const uint8_t CTRL2_GAIN_CALIBRATION = 0x03;
|
34
|
+
static const uint8_t CTRL2_CONFIG_MASK = 0xF0;
|
35
|
+
|
36
|
+
static const uint8_t OCAL1_B2_REG = 0x03;
|
37
|
+
static const uint8_t GCAL1_B3_REG = 0x06;
|
38
|
+
static const uint8_t GCAL1_FRACTIONAL = 23;
|
39
|
+
|
40
|
+
// only need the first data register for sequential read method
|
41
|
+
static const uint8_t ADCO_B2_REG = 0x12;
|
42
|
+
|
43
|
+
static const uint8_t ADC_REG = 0x15;
|
44
|
+
static const uint8_t ADC_CHPS_DISABLE = 0x30;
|
45
|
+
|
46
|
+
static const uint8_t PGA_REG = 0x1B;
|
47
|
+
static const uint8_t PGA_LDOMODE_ESR = 0x40;
|
48
|
+
|
49
|
+
static const uint8_t POWER_REG = 0x1C;
|
50
|
+
static const uint8_t POWER_PGA_CAP_EN = 0x80;
|
51
|
+
|
52
|
+
static const uint8_t DEVICE_REV = 0x1F;
|
53
|
+
|
54
|
+
void NAU7802Sensor::setup() {
|
55
|
+
i2c::I2CRegister pu_ctrl = this->reg(PU_CTRL_REG);
|
56
|
+
ESP_LOGCONFIG(TAG, "Setting up NAU7802 '%s'...", this->name_.c_str());
|
57
|
+
uint8_t rev;
|
58
|
+
|
59
|
+
if (this->read_register(DEVICE_REV | READ_BIT, &rev, 1)) {
|
60
|
+
ESP_LOGE(TAG, "Failed I2C read during setup()");
|
61
|
+
this->mark_failed();
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
ESP_LOGI(TAG, "Setting up NAU7802 Rev %d", rev);
|
65
|
+
|
66
|
+
// reset
|
67
|
+
pu_ctrl |= PU_CTRL_REGISTER_RESET;
|
68
|
+
delay(10);
|
69
|
+
pu_ctrl &= ~PU_CTRL_REGISTER_RESET;
|
70
|
+
|
71
|
+
// power up digital hw
|
72
|
+
pu_ctrl |= PU_CTRL_POWERUP_DIGITAL;
|
73
|
+
|
74
|
+
delay(1);
|
75
|
+
if (!(pu_ctrl.get() & PU_CTRL_POWERUP_READY)) {
|
76
|
+
ESP_LOGE(TAG, "Failed to reset sensor during setup()");
|
77
|
+
this->mark_failed();
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
|
81
|
+
uint32_t gcal = (uint32_t) (round(this->gain_calibration_ * (1 << GCAL1_FRACTIONAL)));
|
82
|
+
this->write_value_(OCAL1_B2_REG, 3, this->offset_calibration_);
|
83
|
+
this->write_value_(GCAL1_B3_REG, 4, gcal);
|
84
|
+
|
85
|
+
// turn on AFE
|
86
|
+
pu_ctrl |= PU_CTRL_POWERUP_ANALOG;
|
87
|
+
auto f = std::bind(&NAU7802Sensor::complete_setup_, this);
|
88
|
+
this->set_timeout(600, f);
|
89
|
+
}
|
90
|
+
|
91
|
+
void NAU7802Sensor::complete_setup_() {
|
92
|
+
i2c::I2CRegister pu_ctrl = this->reg(PU_CTRL_REG);
|
93
|
+
i2c::I2CRegister ctrl1 = this->reg(CTRL1_REG);
|
94
|
+
i2c::I2CRegister ctrl2 = this->reg(CTRL2_REG);
|
95
|
+
pu_ctrl |= PU_CTRL_CYCLE_START;
|
96
|
+
|
97
|
+
// set gain
|
98
|
+
ctrl1 &= ~CTRL1_GAIN_MASK;
|
99
|
+
ctrl1 |= this->gain_;
|
100
|
+
|
101
|
+
// enable internal LDO
|
102
|
+
if (this->ldo_ != NAU7802_LDO_EXTERNAL) {
|
103
|
+
pu_ctrl |= PU_CTRL_AVDD_EXTERNAL;
|
104
|
+
ctrl1 &= ~CTRL1_LDO_MASK;
|
105
|
+
ctrl1 |= this->ldo_ << CTRL1_LDO_SHIFT;
|
106
|
+
}
|
107
|
+
|
108
|
+
// set sps
|
109
|
+
ctrl2 &= ~CTRL2_CRS_MASK;
|
110
|
+
ctrl2 |= this->sps_ << CTRL2_CRS_SHIFT;
|
111
|
+
|
112
|
+
// disable ADC chopper clock
|
113
|
+
i2c::I2CRegister adc_reg = this->reg(ADC_REG);
|
114
|
+
adc_reg |= ADC_CHPS_DISABLE;
|
115
|
+
|
116
|
+
// use low ESR caps
|
117
|
+
i2c::I2CRegister pga_reg = this->reg(PGA_REG);
|
118
|
+
pga_reg &= ~PGA_LDOMODE_ESR;
|
119
|
+
|
120
|
+
// PGA stabilizer cap on output
|
121
|
+
i2c::I2CRegister pwr_reg = this->reg(POWER_REG);
|
122
|
+
pwr_reg |= POWER_PGA_CAP_EN;
|
123
|
+
|
124
|
+
this->setup_complete_ = true;
|
125
|
+
}
|
126
|
+
|
127
|
+
void NAU7802Sensor::dump_config() {
|
128
|
+
LOG_SENSOR("", "NAU7802", this);
|
129
|
+
LOG_I2C_DEVICE(this);
|
130
|
+
|
131
|
+
if (this->is_failed()) {
|
132
|
+
ESP_LOGE(TAG, "Communication with NAU7802 failed earlier, during setup");
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
// Note these may differ from the values on the device if calbration has been run
|
136
|
+
ESP_LOGCONFIG(TAG, " Offset Calibration: %s", to_string(this->offset_calibration_).c_str());
|
137
|
+
ESP_LOGCONFIG(TAG, " Gain Calibration: %f", this->gain_calibration_);
|
138
|
+
|
139
|
+
std::string voltage = "unknown";
|
140
|
+
switch (this->ldo_) {
|
141
|
+
case NAU7802_LDO_2V4:
|
142
|
+
voltage = "2.4V";
|
143
|
+
break;
|
144
|
+
case NAU7802_LDO_2V7:
|
145
|
+
voltage = "2.7V";
|
146
|
+
break;
|
147
|
+
case NAU7802_LDO_3V0:
|
148
|
+
voltage = "3.0V";
|
149
|
+
break;
|
150
|
+
case NAU7802_LDO_3V3:
|
151
|
+
voltage = "3.3V";
|
152
|
+
break;
|
153
|
+
case NAU7802_LDO_3V6:
|
154
|
+
voltage = "3.6V";
|
155
|
+
break;
|
156
|
+
case NAU7802_LDO_3V9:
|
157
|
+
voltage = "3.9V";
|
158
|
+
break;
|
159
|
+
case NAU7802_LDO_4V2:
|
160
|
+
voltage = "4.2V";
|
161
|
+
break;
|
162
|
+
case NAU7802_LDO_4V5:
|
163
|
+
voltage = "4.5V";
|
164
|
+
break;
|
165
|
+
case NAU7802_LDO_EXTERNAL:
|
166
|
+
voltage = "External";
|
167
|
+
break;
|
168
|
+
}
|
169
|
+
ESP_LOGCONFIG(TAG, " LDO Voltage: %s", voltage.c_str());
|
170
|
+
int gain = 0;
|
171
|
+
switch (this->gain_) {
|
172
|
+
case NAU7802_GAIN_128:
|
173
|
+
gain = 128;
|
174
|
+
break;
|
175
|
+
case NAU7802_GAIN_64:
|
176
|
+
gain = 64;
|
177
|
+
break;
|
178
|
+
case NAU7802_GAIN_32:
|
179
|
+
gain = 32;
|
180
|
+
break;
|
181
|
+
case NAU7802_GAIN_16:
|
182
|
+
gain = 16;
|
183
|
+
break;
|
184
|
+
case NAU7802_GAIN_8:
|
185
|
+
gain = 8;
|
186
|
+
break;
|
187
|
+
case NAU7802_GAIN_4:
|
188
|
+
gain = 4;
|
189
|
+
break;
|
190
|
+
case NAU7802_GAIN_2:
|
191
|
+
gain = 2;
|
192
|
+
break;
|
193
|
+
case NAU7802_GAIN_1:
|
194
|
+
gain = 1;
|
195
|
+
break;
|
196
|
+
}
|
197
|
+
ESP_LOGCONFIG(TAG, " Gain: %dx", gain);
|
198
|
+
int sps = 0;
|
199
|
+
switch (this->sps_) {
|
200
|
+
case NAU7802_SPS_320:
|
201
|
+
sps = 320;
|
202
|
+
break;
|
203
|
+
case NAU7802_SPS_80:
|
204
|
+
sps = 80;
|
205
|
+
break;
|
206
|
+
case NAU7802_SPS_40:
|
207
|
+
sps = 40;
|
208
|
+
break;
|
209
|
+
case NAU7802_SPS_20:
|
210
|
+
sps = 20;
|
211
|
+
break;
|
212
|
+
case NAU7802_SPS_10:
|
213
|
+
sps = 10;
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
ESP_LOGCONFIG(TAG, " Samples Per Second: %d", sps);
|
217
|
+
LOG_UPDATE_INTERVAL(this);
|
218
|
+
}
|
219
|
+
|
220
|
+
void NAU7802Sensor::write_value_(uint8_t start_reg, size_t size, int32_t value) {
|
221
|
+
uint8_t data[4];
|
222
|
+
for (int i = 0; i < size; i++) {
|
223
|
+
data[i] = 0xFF & (value >> (size - 1 - i) * 8);
|
224
|
+
}
|
225
|
+
this->write_register(start_reg, data, size);
|
226
|
+
}
|
227
|
+
|
228
|
+
int32_t NAU7802Sensor::read_value_(uint8_t start_reg, size_t size) {
|
229
|
+
uint8_t data[4];
|
230
|
+
this->read_register(start_reg, data, size);
|
231
|
+
int32_t result = 0;
|
232
|
+
for (int i = 0; i < size; i++) {
|
233
|
+
result |= data[i] << (size - 1 - i) * 8;
|
234
|
+
}
|
235
|
+
// extend sign bit
|
236
|
+
if (result & 0x800000 && size == 3) {
|
237
|
+
result |= 0xFF000000;
|
238
|
+
}
|
239
|
+
return result;
|
240
|
+
}
|
241
|
+
|
242
|
+
bool NAU7802Sensor::calibrate_(enum NAU7802CalibrationModes mode) {
|
243
|
+
// check if already calbrating
|
244
|
+
if (this->state_ != CalibrationState::INACTIVE) {
|
245
|
+
ESP_LOGW(TAG, "Calibration already in progress");
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
|
249
|
+
this->state_ = mode == NAU7802_CALIBRATE_GAIN ? CalibrationState::GAIN : CalibrationState::OFFSET;
|
250
|
+
|
251
|
+
i2c::I2CRegister ctrl2 = this->reg(CTRL2_REG);
|
252
|
+
// clear calibraye registers
|
253
|
+
ctrl2 &= CTRL2_CONFIG_MASK;
|
254
|
+
// Calibrate
|
255
|
+
ctrl2 |= mode;
|
256
|
+
ctrl2 |= CTRL2_CALS;
|
257
|
+
return true;
|
258
|
+
}
|
259
|
+
|
260
|
+
void NAU7802Sensor::set_calibration_failure_(bool failed) {
|
261
|
+
switch (this->state_) {
|
262
|
+
case CalibrationState::GAIN:
|
263
|
+
this->gain_calibration_failed_ = failed;
|
264
|
+
break;
|
265
|
+
case CalibrationState::OFFSET:
|
266
|
+
this->offset_calibration_failed_ = failed;
|
267
|
+
break;
|
268
|
+
case CalibrationState::INACTIVE:
|
269
|
+
// shouldn't happen
|
270
|
+
break;
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
void NAU7802Sensor::loop() {
|
275
|
+
i2c::I2CRegister ctrl2 = this->reg(CTRL2_REG);
|
276
|
+
|
277
|
+
if (this->state_ != CalibrationState::INACTIVE && !(ctrl2.get() & CTRL2_CALS)) {
|
278
|
+
if (ctrl2.get() & CTRL2_CAL_ERR) {
|
279
|
+
this->set_calibration_failure_(true);
|
280
|
+
this->state_ = CalibrationState::INACTIVE;
|
281
|
+
ESP_LOGE(TAG, "Failed to calibrate sensor");
|
282
|
+
this->status_set_error("Calibration Failed");
|
283
|
+
return;
|
284
|
+
}
|
285
|
+
|
286
|
+
this->set_calibration_failure_(false);
|
287
|
+
this->state_ = CalibrationState::INACTIVE;
|
288
|
+
|
289
|
+
if (!this->offset_calibration_failed_ && !this->gain_calibration_failed_)
|
290
|
+
this->status_clear_error();
|
291
|
+
|
292
|
+
int32_t ocal = this->read_value_(OCAL1_B2_REG, 3);
|
293
|
+
ESP_LOGI(TAG, "New Offset: %s", to_string(ocal).c_str());
|
294
|
+
uint32_t gcal = this->read_value_(GCAL1_B3_REG, 4);
|
295
|
+
float gcal_f = ((float) gcal / (float) (1 << GCAL1_FRACTIONAL));
|
296
|
+
ESP_LOGI(TAG, "New Gain: %f", gcal_f);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
float NAU7802Sensor::get_setup_priority() const { return setup_priority::DATA; }
|
301
|
+
|
302
|
+
void NAU7802Sensor::update() {
|
303
|
+
if (!this->is_data_ready_()) {
|
304
|
+
ESP_LOGW(TAG, "No measurements ready!");
|
305
|
+
this->status_set_warning();
|
306
|
+
return;
|
307
|
+
}
|
308
|
+
|
309
|
+
this->status_clear_warning();
|
310
|
+
|
311
|
+
// Get the most recent sample to publish
|
312
|
+
int32_t result = this->read_value_(ADCO_B2_REG, 3);
|
313
|
+
|
314
|
+
ESP_LOGD(TAG, "'%s': Got value %" PRId32, this->name_.c_str(), result);
|
315
|
+
this->publish_state(result);
|
316
|
+
}
|
317
|
+
|
318
|
+
bool NAU7802Sensor::is_data_ready_() { return this->reg(PU_CTRL_REG).get() & PU_CTRL_CYCLE_READY; }
|
319
|
+
|
320
|
+
bool NAU7802Sensor::can_proceed() { return this->setup_complete_; }
|
321
|
+
|
322
|
+
} // namespace nau7802
|
323
|
+
} // namespace esphome
|