Refactor Marlin2 component and add new features
- Updated __init__.py to include max_sd_files configuration option. - Refactored Marlin2 class to use new namespaces and improved structure. - Added support for binary sensors and select components in binary_sensor.py and select.py. - Enhanced sensor.py and text_sensor.py to include new configuration options for SD card file count and selected file. - Improved code readability and organization across multiple files.
This commit is contained in:
@@ -7,16 +7,20 @@ from esphome.const import (
|
||||
from . import Marlin2
|
||||
|
||||
CONF_MARLIN = "marlin2"
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
CONF_PRINTER_STATE = "printer_state"
|
||||
CONF_SD_CARD_FILES = "sd_card_files"
|
||||
CONF_SD_CARD_FILE_SELECTED = "sd_card_file_selected"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_MARLIN): cv.use_id(Marlin2),
|
||||
cv.Optional("printer_state"): text_sensor.text_sensor_schema(
|
||||
cv.Optional(CONF_PRINTER_STATE): text_sensor.text_sensor_schema(
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional("sd_card_files"): text_sensor.text_sensor_schema(
|
||||
cv.Optional(CONF_SD_CARD_FILES): text_sensor.text_sensor_schema(
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional("sd_card_file_selected"): text_sensor.text_sensor_schema(
|
||||
cv.Optional(CONF_SD_CARD_FILE_SELECTED): text_sensor.text_sensor_schema(
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
@@ -25,7 +29,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
async def to_code(config):
|
||||
server = await cg.get_variable(config[CONF_MARLIN])
|
||||
|
||||
for sName in ["printer_state", "sd_card_files", "sd_card_file_selected"]:
|
||||
for sName in [CONF_PRINTER_STATE, CONF_SD_CARD_FILES, CONF_SD_CARD_FILE_SELECTED]:
|
||||
if sName in config:
|
||||
sens = await text_sensor.new_text_sensor(config[sName])
|
||||
cg.add(server.add_text_sensor(sName,sens))
|
||||
cg.add(server.add_text_sensor(sName, sens))
|
||||
|
||||
Reference in New Issue
Block a user