esphome/esphomeyaml/components/fan/__init__.py

64 lines
2.2 KiB
Python
Raw Normal View History

2018-04-07 01:23:03 +02:00
import voluptuous as vol
import esphomeyaml.config_validation as cv
2018-05-20 12:41:52 +02:00
from esphomeyaml.const import CONF_ID, CONF_MQTT_ID, CONF_OSCILLATION_COMMAND_TOPIC, \
CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC
from esphomeyaml.helpers import Application, Pvariable, add, esphomelib_ns, setup_mqtt_component
2018-04-07 01:23:03 +02:00
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
2018-05-20 12:41:52 +02:00
})
FAN_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
cv.GenerateID('fan'): cv.register_variable_id,
cv.GenerateID('mqtt_fan', CONF_MQTT_ID): cv.register_variable_id,
2018-04-07 01:23:03 +02:00
vol.Optional(CONF_OSCILLATION_STATE_TOPIC): cv.publish_topic,
vol.Optional(CONF_OSCILLATION_COMMAND_TOPIC): cv.subscribe_topic,
2018-05-20 12:41:52 +02:00
})
fan_ns = esphomelib_ns.namespace('fan')
FanState = fan_ns.FanState
MQTTFanComponent = fan_ns.MQTTFanComponent
MakeFan = Application.MakeFan
2018-05-21 17:01:47 +02:00
TurnOnAction = fan_ns.TurnOnAction
TurnOffAction = fan_ns.TurnOffAction
ToggleAction = fan_ns.ToggleAction
FanSpeed = fan_ns.FanSpeed
FAN_SPEED_OFF = fan_ns.FAN_SPEED_OFF
FAN_SPEED_LOW = fan_ns.FAN_SPEED_LOW
FAN_SPEED_MEDIUM = fan_ns.FAN_SPEED_MEDIUM
FAN_SPEED_HIGH = fan_ns.FAN_SPEED_HIGH
FAN_SPEEDS = {
'OFF': FAN_SPEED_OFF,
'LOW': FAN_SPEED_LOW,
'MEDIUM': FAN_SPEED_MEDIUM,
'HIGH': FAN_SPEED_HIGH,
}
def validate_fan_speed(value):
2018-05-21 20:55:39 +02:00
return vol.All(vol.Upper, cv.one_of(*FAN_SPEEDS))(value)
2018-04-07 01:23:03 +02:00
2018-05-20 12:41:52 +02:00
def setup_fan_core_(fan_var, mqtt_var, config):
2018-04-07 01:23:03 +02:00
if CONF_OSCILLATION_STATE_TOPIC in config:
2018-05-20 12:41:52 +02:00
add(mqtt_var.set_custom_oscillation_state_topic(config[CONF_OSCILLATION_STATE_TOPIC]))
2018-04-07 01:23:03 +02:00
if CONF_OSCILLATION_COMMAND_TOPIC in config:
2018-05-20 12:41:52 +02:00
add(mqtt_var.set_custom_oscillation_command_topic(config[CONF_OSCILLATION_COMMAND_TOPIC]))
2018-04-07 01:23:03 +02:00
if CONF_SPEED_STATE_TOPIC in config:
2018-05-20 12:41:52 +02:00
add(mqtt_var.set_custom_speed_state_topic(config[CONF_SPEED_STATE_TOPIC]))
2018-04-07 01:23:03 +02:00
if CONF_SPEED_COMMAND_TOPIC in config:
2018-05-20 12:41:52 +02:00
add(mqtt_var.set_custom_speed_command_topic(config[CONF_SPEED_COMMAND_TOPIC]))
setup_mqtt_component(mqtt_var, config)
def setup_fan(fan_obj, mqtt_obj, config):
fan_var = Pvariable(FanState, config[CONF_ID], fan_obj, has_side_effects=False)
mqtt_var = Pvariable(MQTTFanComponent, config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
setup_fan_core_(fan_var, mqtt_var, config)
2018-05-06 15:56:12 +02:00
BUILD_FLAGS = '-DUSE_FAN'