Add select
This commit is contained in:
parent
419143d70a
commit
6454dc6d58
@ -14,9 +14,10 @@ OptomaRS232Component = optoma_ns.class_("OptomaRS232Component", cg.PollingCompon
|
|||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
cv.Schema({
|
cv.Schema({
|
||||||
cv.GenerateID(): cv.declare_id(OptomaRS232Component),
|
cv.GenerateID(): cv.declare_id(OptomaRS232Component),
|
||||||
})
|
}).extend(
|
||||||
.extend(cv.polling_component_schema("10s"))
|
cv.polling_component_schema("10s"),
|
||||||
.extend(uart.UART_DEVICE_SCHEMA)
|
uart.UART_DEVICE_SCHEMA
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +56,29 @@ void OptomaRS232Component::update() {
|
|||||||
write_array(reinterpret_cast<const uint8_t *>(QUERIES[last_query_]), strlen(QUERIES[last_query_]));
|
write_array(reinterpret_cast<const uint8_t *>(QUERIES[last_query_]), strlen(QUERIES[last_query_]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptomaRS232Component::beamer_input_select_changed(const std::string &state, size_t) {
|
||||||
|
const char *data;
|
||||||
|
Inputs inp{UNKNOWN};
|
||||||
|
if (state == "Unknown")
|
||||||
|
return;
|
||||||
|
if (state == "HDMI 1") {
|
||||||
|
inp = HDMI_1;
|
||||||
|
data = "~0012 1\r";
|
||||||
|
} else if (state == "HDMI 2") {
|
||||||
|
inp = HDMI_2;
|
||||||
|
data = "~0012 15\r";
|
||||||
|
} else if (state == "VGA") {
|
||||||
|
inp = VGA;
|
||||||
|
data = "~0012 5\r"; // VGA 1
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (inp == current_input_)
|
||||||
|
return;
|
||||||
|
current_input_ = inp;
|
||||||
|
write_array(reinterpret_cast<const uint8_t *>(data), strlen(data));
|
||||||
|
}
|
||||||
|
|
||||||
void OptomaRS232Component::process_line_(const std::string &str) {
|
void OptomaRS232Component::process_line_(const std::string &str) {
|
||||||
// if we are waiting for the projector to respond to a command.
|
// if we are waiting for the projector to respond to a command.
|
||||||
// it will respond P (pass) or F (fail) before giving us the actual response to the command.
|
// it will respond P (pass) or F (fail) before giving us the actual response to the command.
|
||||||
@ -110,19 +133,23 @@ void OptomaRS232Component::process_query_response_(const std::string &str) {
|
|||||||
// publish(beamer_firmware_,strtol(buf + 10, 0, 10));
|
// publish(beamer_firmware_,strtol(buf + 10, 0, 10));
|
||||||
buf[10] = 0;
|
buf[10] = 0;
|
||||||
|
|
||||||
int input = -1; // atol(buf + 8); BUGGY
|
int input = strtol(buf + 8, 0, 10); // BUGGY
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case Inputs::HDMI_1:
|
case Inputs::HDMI_1:
|
||||||
|
current_input_ = Inputs::HDMI_1;
|
||||||
publish(beamer_input_text_sensor_, "HDMI 1");
|
publish(beamer_input_text_sensor_, "HDMI 1");
|
||||||
break;
|
break;
|
||||||
case Inputs::HDMI_2:
|
case Inputs::HDMI_2:
|
||||||
|
current_input_ = Inputs::HDMI_2;
|
||||||
publish(beamer_input_text_sensor_, "HDMI 2");
|
publish(beamer_input_text_sensor_, "HDMI 2");
|
||||||
break;
|
break;
|
||||||
case Inputs::VGA:
|
case Inputs::VGA:
|
||||||
|
current_input_ = Inputs::VGA;
|
||||||
publish(beamer_input_text_sensor_, "VGA");
|
publish(beamer_input_text_sensor_, "VGA");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case Inputs::UNKNOWN:
|
case Inputs::UNKNOWN:
|
||||||
|
current_input_ = Inputs::UNKNOWN;
|
||||||
publish(beamer_input_text_sensor_, "Unknown");
|
publish(beamer_input_text_sensor_, "Unknown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -139,5 +166,14 @@ void OptomaRS232Component::process_query_response_(const std::string &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_SELECT
|
||||||
|
void InputSelect::control(const std::string &value) {
|
||||||
|
this->publish_state(value);
|
||||||
|
auto index = this->index_of(value);
|
||||||
|
if (index.has_value())
|
||||||
|
this->parent_->beamer_input_select_changed(value, *index);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace optoma_rs232
|
} // namespace optoma_rs232
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
@ -36,6 +36,7 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
|
|||||||
void loop() override;
|
void loop() override;
|
||||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||||
void update() override;
|
void update() override;
|
||||||
|
void beamer_input_select_changed(const std::string &, size_t);
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#ifndef USE_SENSOR
|
#ifndef USE_SENSOR
|
||||||
@ -61,6 +62,8 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
|
|||||||
SUB_SELECT(beamer_input)
|
SUB_SELECT(beamer_input)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Inputs current_input_{UNKNOWN};
|
||||||
|
|
||||||
void process_line_(const std::string &str);
|
void process_line_(const std::string &str);
|
||||||
void process_query_response_(const std::string &str);
|
void process_query_response_(const std::string &str);
|
||||||
bool waiting_for_command_response_ = false;
|
bool waiting_for_command_response_ = false;
|
||||||
@ -71,5 +74,12 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
|
|||||||
size_t cursor_ = 0;
|
size_t cursor_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_SELECT
|
||||||
|
class InputSelect : public select::Select, public Parented<OptomaRS232Component> {
|
||||||
|
protected:
|
||||||
|
void control(const std::string &value) override;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace optoma_rs232
|
} // namespace optoma_rs232
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
@ -6,6 +6,8 @@ from . import CONF_OPTOMA_RS232_ID, OptomaRS232Component, optoma_ns
|
|||||||
|
|
||||||
DEPENDENCIES = ["optoma_rs232"]
|
DEPENDENCIES = ["optoma_rs232"]
|
||||||
|
|
||||||
|
InputSelect = optoma_ns.class_("InputSelect", select.Select)
|
||||||
|
|
||||||
Inputs = optoma_ns.enum("Inputs")
|
Inputs = optoma_ns.enum("Inputs")
|
||||||
INPUT_OPTIONS = {
|
INPUT_OPTIONS = {
|
||||||
"Unknown": 0,
|
"Unknown": 0,
|
||||||
@ -14,8 +16,7 @@ INPUT_OPTIONS = {
|
|||||||
"HDMI 2": 8,
|
"HDMI 2": 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_SCHEMA = select.select_schema(
|
CONFIG_SCHEMA = select.select_schema(InputSelect).extend({
|
||||||
).extend({
|
|
||||||
cv.GenerateID(CONF_OPTOMA_RS232_ID): cv.use_id(OptomaRS232Component),
|
cv.GenerateID(CONF_OPTOMA_RS232_ID): cv.use_id(OptomaRS232Component),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ from . import CONF_OPTOMA_RS232_ID, optoma_ns, OptomaRS232Component
|
|||||||
DEPENDENCIES = ["optoma_rs232"]
|
DEPENDENCIES = ["optoma_rs232"]
|
||||||
|
|
||||||
CONF_FAN_SPEED = "fan_speed"
|
CONF_FAN_SPEED = "fan_speed"
|
||||||
|
CONF_LAMP_TIME = "lamp_hours"
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
cv.Schema({
|
cv.Schema({
|
||||||
@ -29,7 +30,7 @@ CONFIG_SCHEMA = (
|
|||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_DURATION): sensor.sensor_schema(
|
cv.Optional(CONF_LAMP_TIME): sensor.sensor_schema(
|
||||||
unit_of_measurement=UNIT_HOUR,
|
unit_of_measurement=UNIT_HOUR,
|
||||||
accuracy_decimals=0,
|
accuracy_decimals=0,
|
||||||
device_class=DEVICE_CLASS_DURATION,
|
device_class=DEVICE_CLASS_DURATION,
|
||||||
@ -42,8 +43,10 @@ CONFIG_SCHEMA = (
|
|||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
.extend(cv.polling_component_schema("10s"))
|
.extend(
|
||||||
.extend(uart.UART_DEVICE_SCHEMA)
|
cv.polling_component_schema("10s"),
|
||||||
|
uart.UART_DEVICE_SCHEMA
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ from . import CONF_OPTOMA_RS232_ID, OptomaRS232Component
|
|||||||
|
|
||||||
DEPENDENCIES = ["optoma_rs232"]
|
DEPENDENCIES = ["optoma_rs232"]
|
||||||
|
|
||||||
CONFIG_SCHEMA = text_sensor.text_sensor_schema(
|
CONFIG_SCHEMA = text_sensor.text_sensor_schema().extend({
|
||||||
).extend({
|
|
||||||
cv.GenerateID(CONF_OPTOMA_RS232_ID): cv.use_id(OptomaRS232Component),
|
cv.GenerateID(CONF_OPTOMA_RS232_ID): cv.use_id(OptomaRS232Component),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user