-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Component file structure refactor (#3)
* Refactor separate switch component into nested switch component * Refactor separate button component into nested button component * Refactor separate binary_sensor component into nested binary_sensor component * Refactor separate sensor component into nested sensor component * Refactor switch and button component to be in-line with ESPHomes standard
- Loading branch information
1 parent
22a86fe
commit 3308c07
Showing
22 changed files
with
285 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import button | ||
from esphome.const import CONF_ID | ||
|
||
from .. import CONF_DESK_ID, GenericDesk | ||
|
||
DEPENDENCIES = ["generic_desk"] | ||
|
||
CONF_MEMORY_ID_1 = "M1" | ||
CONF_MEMORY_ID_2 = "M2" | ||
CONF_MEMORY_ID_3 = "M3" | ||
CONF_MEMORY_ID_4 = "M4" | ||
|
||
ID_CONFIGS = [ | ||
CONF_MEMORY_ID_1, | ||
CONF_MEMORY_ID_2, | ||
CONF_MEMORY_ID_3, | ||
CONF_MEMORY_ID_4, | ||
] | ||
|
||
memory_button_ns = cg.esphome_ns.namespace("memory_button") | ||
MemoryButton = memory_button_ns.class_("MemoryButton", button.Button, cg.Component) | ||
|
||
BUTTON_CONFIG = button.BUTTON_SCHEMA.extend( | ||
{cv.GenerateID(): cv.declare_id(MemoryButton)} | ||
).extend(cv.COMPONENT_SCHEMA) | ||
|
||
CONFIG_SCHEMA = cv.All( | ||
cv.Schema( | ||
{ | ||
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk), | ||
cv.Optional(CONF_MEMORY_ID_1): BUTTON_CONFIG, | ||
cv.Optional(CONF_MEMORY_ID_2): BUTTON_CONFIG, | ||
cv.Optional(CONF_MEMORY_ID_3): BUTTON_CONFIG, | ||
cv.Optional(CONF_MEMORY_ID_4): BUTTON_CONFIG, | ||
} | ||
), | ||
cv.has_at_least_one_key(*ID_CONFIGS), | ||
) | ||
|
||
|
||
async def to_code(config): | ||
parent = await cg.get_variable(config[CONF_DESK_ID]) | ||
|
||
for id, config_id in enumerate(ID_CONFIGS): | ||
if button_config := config.get(config_id): | ||
var = await button.new_button(button_config) | ||
cg.add(var.set_memory_id(id)) | ||
cg.add(parent.add_button(var)) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.