-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial switch implementation (not working yet)
- Loading branch information
Pavlo Dudnytskyi
committed
Jul 31, 2024
1 parent
60d926c
commit 2ba4c95
Showing
4 changed files
with
74 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import switch | ||
from esphome.const import ( | ||
CONF_BEEPER, | ||
CONF_DISPLAY, | ||
ENTITY_CATEGORY_CONFIG, | ||
) | ||
from ..climate import ( | ||
CONF_HAIER_ID, | ||
HaierClimateBase, | ||
HonClimate, | ||
haier_ns, | ||
) | ||
|
||
CODEOWNERS = ["@paveldn"] | ||
BeeperSwitch = haier_ns.class_("BeeperSwitch", switch.Switch) | ||
HealthModeSwitch = haier_ns.class_("HealthModeSwitch", switch.Switch) | ||
DisplaySwitch = haier_ns.class_("DisplaySwitch", switch.Switch) | ||
|
||
# Haier switches | ||
CONF_HEALTH_MODE = "health_mode" | ||
|
||
# Additional icons | ||
ICON_LEAF = "mdi:leaf" | ||
ICON_LED_ON = "mdi:led-on" | ||
ICON_VOLUME_HIGH = "mdi:volume-high" | ||
|
||
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(CONF_HAIER_ID): cv.use_id(HaierClimateBase), | ||
cv.Optional(CONF_DISPLAY): switch.switch_schema( | ||
DisplaySwitch, | ||
icon=ICON_LED_ON, | ||
entity_category=ENTITY_CATEGORY_CONFIG, | ||
), | ||
cv.Optional(CONF_HEALTH_MODE): switch.switch_schema( | ||
HealthModeSwitch, | ||
icon=ICON_LEAF, | ||
), | ||
cv.Optional(CONF_BEEPER): switch.switch_schema( | ||
BeeperSwitch, | ||
icon=ICON_VOLUME_HIGH, | ||
entity_category=ENTITY_CATEGORY_CONFIG, | ||
), | ||
} | ||
) | ||
|
||
from esphome.cpp_generator import MockObjClass | ||
|
||
|
||
async def to_code(config): | ||
full_id, parent = await cg.get_variable_with_full_id(config[CONF_HAIER_ID]) | ||
|
||
for switch_type in [CONF_DISPLAY, CONF_HEALTH_MODE]: | ||
if conf := config.get(switch_type): | ||
swtch = await switch.new_switch(conf) | ||
await cg.register_parented(swtch, parent) | ||
if conf := config.get(CONF_BEEPER): | ||
if full_id.type is HonClimate: | ||
swtch = await switch.new_switch(conf) | ||
await cg.register_parented(swtch, parent) | ||
else: | ||
raise ValueError("Beeper switch is only supported for hon climate") | ||
|
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 |
---|---|---|
@@ -1,13 +1,4 @@ | ||
switch: | ||
- platform: template | ||
id: ${device_id}_beeper_switch | ||
entity_category: config | ||
name: ${device_name} beeper | ||
icon: mdi:volume-high | ||
restore_mode: RESTORE_DEFAULT_ON | ||
lambda: |- | ||
return id(${device_id}).get_beeper_state(); | ||
turn_on_action: | ||
climate.haier.beeper_on: ${device_id} | ||
turn_off_action: | ||
climate.haier.beeper_off: ${device_id} | ||
- platform: haier | ||
beeper: | ||
name: ${device_name} beeper |
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 |
---|---|---|
@@ -1,13 +1,4 @@ | ||
switch: | ||
- platform: template | ||
id: ${device_id}_display_switch | ||
name: ${device_name} display | ||
icon: mdi:led-on | ||
entity_category: config | ||
restore_mode: RESTORE_DEFAULT_ON | ||
lambda: |- | ||
return id(${device_id}).get_display_state(); | ||
turn_on_action: | ||
climate.haier.display_on: ${device_id} | ||
turn_off_action: | ||
climate.haier.display_off: ${device_id} | ||
- platform: haier | ||
display: | ||
name: ${device_name} display |
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 |
---|---|---|
@@ -1,12 +1,4 @@ | ||
switch: | ||
- platform: template | ||
id: ${device_id}_health_mode | ||
name: ${device_name} health mode | ||
icon: mdi:leaf | ||
restore_mode: RESTORE_DEFAULT_OFF | ||
lambda: |- | ||
return id(${device_id}).get_health_mode(); | ||
turn_on_action: | ||
climate.haier.health_on: ${device_id} | ||
turn_off_action: | ||
climate.haier.health_off: ${device_id} | ||
- platform: haier | ||
health_mode: | ||
name: ${device_name} health mode |