mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	Merge branch 'api_reduce' into integration
This commit is contained in:
		| @@ -9,155 +9,85 @@ | |||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace api { | namespace api { | ||||||
|  |  | ||||||
|  | // Generate entity handler implementations using macros | ||||||
| #ifdef USE_BINARY_SENSOR | #ifdef USE_BINARY_SENSOR | ||||||
| bool ListEntitiesIterator::on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) { | LIST_ENTITIES_HANDLER(binary_sensor, binary_sensor::BinarySensor, ListEntitiesBinarySensorResponse) | ||||||
|   return this->client_->schedule_message_(binary_sensor, &APIConnection::try_send_binary_sensor_info, |  | ||||||
|                                           ListEntitiesBinarySensorResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_COVER | #ifdef USE_COVER | ||||||
| bool ListEntitiesIterator::on_cover(cover::Cover *cover) { | LIST_ENTITIES_HANDLER(cover, cover::Cover, ListEntitiesCoverResponse) | ||||||
|   return this->client_->schedule_message_(cover, &APIConnection::try_send_cover_info, |  | ||||||
|                                           ListEntitiesCoverResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_FAN | #ifdef USE_FAN | ||||||
| bool ListEntitiesIterator::on_fan(fan::Fan *fan) { | LIST_ENTITIES_HANDLER(fan, fan::Fan, ListEntitiesFanResponse) | ||||||
|   return this->client_->schedule_message_(fan, &APIConnection::try_send_fan_info, |  | ||||||
|                                           ListEntitiesFanResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LIGHT | #ifdef USE_LIGHT | ||||||
| bool ListEntitiesIterator::on_light(light::LightState *light) { | LIST_ENTITIES_HANDLER(light, light::LightState, ListEntitiesLightResponse) | ||||||
|   return this->client_->schedule_message_(light, &APIConnection::try_send_light_info, |  | ||||||
|                                           ListEntitiesLightResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SENSOR | #ifdef USE_SENSOR | ||||||
| bool ListEntitiesIterator::on_sensor(sensor::Sensor *sensor) { | LIST_ENTITIES_HANDLER(sensor, sensor::Sensor, ListEntitiesSensorResponse) | ||||||
|   return this->client_->schedule_message_(sensor, &APIConnection::try_send_sensor_info, |  | ||||||
|                                           ListEntitiesSensorResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SWITCH | #ifdef USE_SWITCH | ||||||
| bool ListEntitiesIterator::on_switch(switch_::Switch *a_switch) { | LIST_ENTITIES_HANDLER(switch, switch_::Switch, ListEntitiesSwitchResponse) | ||||||
|   return this->client_->schedule_message_(a_switch, &APIConnection::try_send_switch_info, |  | ||||||
|                                           ListEntitiesSwitchResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_BUTTON | #ifdef USE_BUTTON | ||||||
| bool ListEntitiesIterator::on_button(button::Button *button) { | LIST_ENTITIES_HANDLER(button, button::Button, ListEntitiesButtonResponse) | ||||||
|   return this->client_->schedule_message_(button, &APIConnection::try_send_button_info, |  | ||||||
|                                           ListEntitiesButtonResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT_SENSOR | #ifdef USE_TEXT_SENSOR | ||||||
| bool ListEntitiesIterator::on_text_sensor(text_sensor::TextSensor *text_sensor) { | LIST_ENTITIES_HANDLER(text_sensor, text_sensor::TextSensor, ListEntitiesTextSensorResponse) | ||||||
|   return this->client_->schedule_message_(text_sensor, &APIConnection::try_send_text_sensor_info, |  | ||||||
|                                           ListEntitiesTextSensorResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LOCK | #ifdef USE_LOCK | ||||||
| bool ListEntitiesIterator::on_lock(lock::Lock *a_lock) { | LIST_ENTITIES_HANDLER(lock, lock::Lock, ListEntitiesLockResponse) | ||||||
|   return this->client_->schedule_message_(a_lock, &APIConnection::try_send_lock_info, |  | ||||||
|                                           ListEntitiesLockResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_VALVE | #ifdef USE_VALVE | ||||||
| bool ListEntitiesIterator::on_valve(valve::Valve *valve) { | LIST_ENTITIES_HANDLER(valve, valve::Valve, ListEntitiesValveResponse) | ||||||
|   return this->client_->schedule_message_(valve, &APIConnection::try_send_valve_info, | #endif | ||||||
|                                           ListEntitiesValveResponse::MESSAGE_TYPE); | #ifdef USE_ESP32_CAMERA | ||||||
| } | LIST_ENTITIES_HANDLER(camera, esp32_camera::ESP32Camera, ListEntitiesCameraResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_CLIMATE | ||||||
|  | LIST_ENTITIES_HANDLER(climate, climate::Climate, ListEntitiesClimateResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_NUMBER | ||||||
|  | LIST_ENTITIES_HANDLER(number, number::Number, ListEntitiesNumberResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DATETIME_DATE | ||||||
|  | LIST_ENTITIES_HANDLER(date, datetime::DateEntity, ListEntitiesDateResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DATETIME_TIME | ||||||
|  | LIST_ENTITIES_HANDLER(time, datetime::TimeEntity, ListEntitiesTimeResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DATETIME_DATETIME | ||||||
|  | LIST_ENTITIES_HANDLER(datetime, datetime::DateTimeEntity, ListEntitiesDateTimeResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_TEXT | ||||||
|  | LIST_ENTITIES_HANDLER(text, text::Text, ListEntitiesTextResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_SELECT | ||||||
|  | LIST_ENTITIES_HANDLER(select, select::Select, ListEntitiesSelectResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_MEDIA_PLAYER | ||||||
|  | LIST_ENTITIES_HANDLER(media_player, media_player::MediaPlayer, ListEntitiesMediaPlayerResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_ALARM_CONTROL_PANEL | ||||||
|  | LIST_ENTITIES_HANDLER(alarm_control_panel, alarm_control_panel::AlarmControlPanel, | ||||||
|  |                       ListEntitiesAlarmControlPanelResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_EVENT | ||||||
|  | LIST_ENTITIES_HANDLER(event, event::Event, ListEntitiesEventResponse) | ||||||
|  | #endif | ||||||
|  | #ifdef USE_UPDATE | ||||||
|  | LIST_ENTITIES_HANDLER(update, update::UpdateEntity, ListEntitiesUpdateResponse) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | // Special cases that don't follow the pattern | ||||||
| bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done(); } | bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done(); } | ||||||
|  |  | ||||||
| ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {} | ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {} | ||||||
|  |  | ||||||
| bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) { | bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) { | ||||||
|   auto resp = service->encode_list_service_response(); |   auto resp = service->encode_list_service_response(); | ||||||
|   return this->client_->send_message(resp); |   return this->client_->send_message(resp); | ||||||
| } | } | ||||||
|  |  | ||||||
| #ifdef USE_ESP32_CAMERA |  | ||||||
| bool ListEntitiesIterator::on_camera(esp32_camera::ESP32Camera *camera) { |  | ||||||
|   return this->client_->schedule_message_(camera, &APIConnection::try_send_camera_info, |  | ||||||
|                                           ListEntitiesCameraResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_CLIMATE |  | ||||||
| bool ListEntitiesIterator::on_climate(climate::Climate *climate) { |  | ||||||
|   return this->client_->schedule_message_(climate, &APIConnection::try_send_climate_info, |  | ||||||
|                                           ListEntitiesClimateResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_NUMBER |  | ||||||
| bool ListEntitiesIterator::on_number(number::Number *number) { |  | ||||||
|   return this->client_->schedule_message_(number, &APIConnection::try_send_number_info, |  | ||||||
|                                           ListEntitiesNumberResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_DATETIME_DATE |  | ||||||
| bool ListEntitiesIterator::on_date(datetime::DateEntity *date) { |  | ||||||
|   return this->client_->schedule_message_(date, &APIConnection::try_send_date_info, |  | ||||||
|                                           ListEntitiesDateResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_DATETIME_TIME |  | ||||||
| bool ListEntitiesIterator::on_time(datetime::TimeEntity *time) { |  | ||||||
|   return this->client_->schedule_message_(time, &APIConnection::try_send_time_info, |  | ||||||
|                                           ListEntitiesTimeResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_DATETIME_DATETIME |  | ||||||
| bool ListEntitiesIterator::on_datetime(datetime::DateTimeEntity *datetime) { |  | ||||||
|   return this->client_->schedule_message_(datetime, &APIConnection::try_send_datetime_info, |  | ||||||
|                                           ListEntitiesDateTimeResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_TEXT |  | ||||||
| bool ListEntitiesIterator::on_text(text::Text *text) { |  | ||||||
|   return this->client_->schedule_message_(text, &APIConnection::try_send_text_info, |  | ||||||
|                                           ListEntitiesTextResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_SELECT |  | ||||||
| bool ListEntitiesIterator::on_select(select::Select *select) { |  | ||||||
|   return this->client_->schedule_message_(select, &APIConnection::try_send_select_info, |  | ||||||
|                                           ListEntitiesSelectResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef USE_MEDIA_PLAYER |  | ||||||
| bool ListEntitiesIterator::on_media_player(media_player::MediaPlayer *media_player) { |  | ||||||
|   return this->client_->schedule_message_(media_player, &APIConnection::try_send_media_player_info, |  | ||||||
|                                           ListEntitiesMediaPlayerResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| #ifdef USE_ALARM_CONTROL_PANEL |  | ||||||
| bool ListEntitiesIterator::on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) { |  | ||||||
|   return this->client_->schedule_message_(a_alarm_control_panel, &APIConnection::try_send_alarm_control_panel_info, |  | ||||||
|                                           ListEntitiesAlarmControlPanelResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| #ifdef USE_EVENT |  | ||||||
| bool ListEntitiesIterator::on_event(event::Event *event) { |  | ||||||
|   return this->client_->schedule_message_(event, &APIConnection::try_send_event_info, |  | ||||||
|                                           ListEntitiesEventResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| #ifdef USE_UPDATE |  | ||||||
| bool ListEntitiesIterator::on_update(update::UpdateEntity *update) { |  | ||||||
|   return this->client_->schedule_message_(update, &APIConnection::try_send_update_info, |  | ||||||
|                                           ListEntitiesUpdateResponse::MESSAGE_TYPE); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| }  // namespace api | }  // namespace api | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -9,75 +9,85 @@ namespace api { | |||||||
|  |  | ||||||
| class APIConnection; | class APIConnection; | ||||||
|  |  | ||||||
|  | // Macro for generating ListEntitiesIterator handlers | ||||||
|  | // Calls schedule_message_ with try_send_*_info | ||||||
|  | // clang-format off | ||||||
|  | #define LIST_ENTITIES_HANDLER(entity_type, EntityClass, ResponseType) \ | ||||||
|  |   bool ListEntitiesIterator::on_##entity_type(EntityClass *entity) { \ | ||||||
|  |     return this->client_->schedule_message_(entity, &APIConnection::try_send_##entity_type##_info, \ | ||||||
|  |                                             ResponseType::MESSAGE_TYPE); \ | ||||||
|  |   } | ||||||
|  | // clang-format on | ||||||
|  |  | ||||||
| class ListEntitiesIterator : public ComponentIterator { | class ListEntitiesIterator : public ComponentIterator { | ||||||
|  public: |  public: | ||||||
|   ListEntitiesIterator(APIConnection *client); |   ListEntitiesIterator(APIConnection *client); | ||||||
| #ifdef USE_BINARY_SENSOR | #ifdef USE_BINARY_SENSOR | ||||||
|   bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) override; |   bool on_binary_sensor(binary_sensor::BinarySensor *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_COVER | #ifdef USE_COVER | ||||||
|   bool on_cover(cover::Cover *cover) override; |   bool on_cover(cover::Cover *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_FAN | #ifdef USE_FAN | ||||||
|   bool on_fan(fan::Fan *fan) override; |   bool on_fan(fan::Fan *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LIGHT | #ifdef USE_LIGHT | ||||||
|   bool on_light(light::LightState *light) override; |   bool on_light(light::LightState *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SENSOR | #ifdef USE_SENSOR | ||||||
|   bool on_sensor(sensor::Sensor *sensor) override; |   bool on_sensor(sensor::Sensor *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SWITCH | #ifdef USE_SWITCH | ||||||
|   bool on_switch(switch_::Switch *a_switch) override; |   bool on_switch(switch_::Switch *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_BUTTON | #ifdef USE_BUTTON | ||||||
|   bool on_button(button::Button *button) override; |   bool on_button(button::Button *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT_SENSOR | #ifdef USE_TEXT_SENSOR | ||||||
|   bool on_text_sensor(text_sensor::TextSensor *text_sensor) override; |   bool on_text_sensor(text_sensor::TextSensor *entity) override; | ||||||
| #endif | #endif | ||||||
|   bool on_service(UserServiceDescriptor *service) override; |   bool on_service(UserServiceDescriptor *service) override; | ||||||
| #ifdef USE_ESP32_CAMERA | #ifdef USE_ESP32_CAMERA | ||||||
|   bool on_camera(esp32_camera::ESP32Camera *camera) override; |   bool on_camera(esp32_camera::ESP32Camera *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_CLIMATE | #ifdef USE_CLIMATE | ||||||
|   bool on_climate(climate::Climate *climate) override; |   bool on_climate(climate::Climate *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_NUMBER | #ifdef USE_NUMBER | ||||||
|   bool on_number(number::Number *number) override; |   bool on_number(number::Number *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATE | #ifdef USE_DATETIME_DATE | ||||||
|   bool on_date(datetime::DateEntity *date) override; |   bool on_date(datetime::DateEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_TIME | #ifdef USE_DATETIME_TIME | ||||||
|   bool on_time(datetime::TimeEntity *time) override; |   bool on_time(datetime::TimeEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATETIME | #ifdef USE_DATETIME_DATETIME | ||||||
|   bool on_datetime(datetime::DateTimeEntity *datetime) override; |   bool on_datetime(datetime::DateTimeEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT | #ifdef USE_TEXT | ||||||
|   bool on_text(text::Text *text) override; |   bool on_text(text::Text *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SELECT | #ifdef USE_SELECT | ||||||
|   bool on_select(select::Select *select) override; |   bool on_select(select::Select *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LOCK | #ifdef USE_LOCK | ||||||
|   bool on_lock(lock::Lock *a_lock) override; |   bool on_lock(lock::Lock *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_VALVE | #ifdef USE_VALVE | ||||||
|   bool on_valve(valve::Valve *valve) override; |   bool on_valve(valve::Valve *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_MEDIA_PLAYER | #ifdef USE_MEDIA_PLAYER | ||||||
|   bool on_media_player(media_player::MediaPlayer *media_player) override; |   bool on_media_player(media_player::MediaPlayer *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_ALARM_CONTROL_PANEL | #ifdef USE_ALARM_CONTROL_PANEL | ||||||
|   bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override; |   bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_EVENT | #ifdef USE_EVENT | ||||||
|   bool on_event(event::Event *event) override; |   bool on_event(event::Event *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_UPDATE | #ifdef USE_UPDATE | ||||||
|   bool on_update(update::UpdateEntity *update) override; |   bool on_update(update::UpdateEntity *entity) override; | ||||||
| #endif | #endif | ||||||
|   bool on_end() override; |   bool on_end() override; | ||||||
|   bool completed() { return this->state_ == IteratorState::NONE; } |   bool completed() { return this->state_ == IteratorState::NONE; } | ||||||
|   | |||||||
| @@ -6,73 +6,67 @@ | |||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace api { | namespace api { | ||||||
|  |  | ||||||
|  | // Generate entity handler implementations using macros | ||||||
| #ifdef USE_BINARY_SENSOR | #ifdef USE_BINARY_SENSOR | ||||||
| bool InitialStateIterator::on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) { | INITIAL_STATE_HANDLER(binary_sensor, binary_sensor::BinarySensor) | ||||||
|   return this->client_->send_binary_sensor_state(binary_sensor); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_COVER | #ifdef USE_COVER | ||||||
| bool InitialStateIterator::on_cover(cover::Cover *cover) { return this->client_->send_cover_state(cover); } | INITIAL_STATE_HANDLER(cover, cover::Cover) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_FAN | #ifdef USE_FAN | ||||||
| bool InitialStateIterator::on_fan(fan::Fan *fan) { return this->client_->send_fan_state(fan); } | INITIAL_STATE_HANDLER(fan, fan::Fan) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LIGHT | #ifdef USE_LIGHT | ||||||
| bool InitialStateIterator::on_light(light::LightState *light) { return this->client_->send_light_state(light); } | INITIAL_STATE_HANDLER(light, light::LightState) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SENSOR | #ifdef USE_SENSOR | ||||||
| bool InitialStateIterator::on_sensor(sensor::Sensor *sensor) { return this->client_->send_sensor_state(sensor); } | INITIAL_STATE_HANDLER(sensor, sensor::Sensor) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SWITCH | #ifdef USE_SWITCH | ||||||
| bool InitialStateIterator::on_switch(switch_::Switch *a_switch) { return this->client_->send_switch_state(a_switch); } | INITIAL_STATE_HANDLER(switch, switch_::Switch) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT_SENSOR | #ifdef USE_TEXT_SENSOR | ||||||
| bool InitialStateIterator::on_text_sensor(text_sensor::TextSensor *text_sensor) { | INITIAL_STATE_HANDLER(text_sensor, text_sensor::TextSensor) | ||||||
|   return this->client_->send_text_sensor_state(text_sensor); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_CLIMATE | #ifdef USE_CLIMATE | ||||||
| bool InitialStateIterator::on_climate(climate::Climate *climate) { return this->client_->send_climate_state(climate); } | INITIAL_STATE_HANDLER(climate, climate::Climate) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_NUMBER | #ifdef USE_NUMBER | ||||||
| bool InitialStateIterator::on_number(number::Number *number) { return this->client_->send_number_state(number); } | INITIAL_STATE_HANDLER(number, number::Number) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATE | #ifdef USE_DATETIME_DATE | ||||||
| bool InitialStateIterator::on_date(datetime::DateEntity *date) { return this->client_->send_date_state(date); } | INITIAL_STATE_HANDLER(date, datetime::DateEntity) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_TIME | #ifdef USE_DATETIME_TIME | ||||||
| bool InitialStateIterator::on_time(datetime::TimeEntity *time) { return this->client_->send_time_state(time); } | INITIAL_STATE_HANDLER(time, datetime::TimeEntity) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATETIME | #ifdef USE_DATETIME_DATETIME | ||||||
| bool InitialStateIterator::on_datetime(datetime::DateTimeEntity *datetime) { | INITIAL_STATE_HANDLER(datetime, datetime::DateTimeEntity) | ||||||
|   return this->client_->send_datetime_state(datetime); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT | #ifdef USE_TEXT | ||||||
| bool InitialStateIterator::on_text(text::Text *text) { return this->client_->send_text_state(text); } | INITIAL_STATE_HANDLER(text, text::Text) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SELECT | #ifdef USE_SELECT | ||||||
| bool InitialStateIterator::on_select(select::Select *select) { return this->client_->send_select_state(select); } | INITIAL_STATE_HANDLER(select, select::Select) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LOCK | #ifdef USE_LOCK | ||||||
| bool InitialStateIterator::on_lock(lock::Lock *a_lock) { return this->client_->send_lock_state(a_lock); } | INITIAL_STATE_HANDLER(lock, lock::Lock) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_VALVE | #ifdef USE_VALVE | ||||||
| bool InitialStateIterator::on_valve(valve::Valve *valve) { return this->client_->send_valve_state(valve); } | INITIAL_STATE_HANDLER(valve, valve::Valve) | ||||||
| #endif | #endif | ||||||
| #ifdef USE_MEDIA_PLAYER | #ifdef USE_MEDIA_PLAYER | ||||||
| bool InitialStateIterator::on_media_player(media_player::MediaPlayer *media_player) { | INITIAL_STATE_HANDLER(media_player, media_player::MediaPlayer) | ||||||
|   return this->client_->send_media_player_state(media_player); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_ALARM_CONTROL_PANEL | #ifdef USE_ALARM_CONTROL_PANEL | ||||||
| bool InitialStateIterator::on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) { | INITIAL_STATE_HANDLER(alarm_control_panel, alarm_control_panel::AlarmControlPanel) | ||||||
|   return this->client_->send_alarm_control_panel_state(a_alarm_control_panel); |  | ||||||
| } |  | ||||||
| #endif | #endif | ||||||
| #ifdef USE_UPDATE | #ifdef USE_UPDATE | ||||||
| bool InitialStateIterator::on_update(update::UpdateEntity *update) { return this->client_->send_update_state(update); } | INITIAL_STATE_HANDLER(update, update::UpdateEntity) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | // Special cases (button and event) are already defined inline in subscribe_state.h | ||||||
|  |  | ||||||
| InitialStateIterator::InitialStateIterator(APIConnection *client) : client_(client) {} | InitialStateIterator::InitialStateIterator(APIConnection *client) : client_(client) {} | ||||||
|  |  | ||||||
| }  // namespace api | }  // namespace api | ||||||
|   | |||||||
| @@ -10,71 +10,80 @@ namespace api { | |||||||
|  |  | ||||||
| class APIConnection; | class APIConnection; | ||||||
|  |  | ||||||
|  | // Macro for generating InitialStateIterator handlers | ||||||
|  | // Calls send_*_state | ||||||
|  | // clang-format off | ||||||
|  | #define INITIAL_STATE_HANDLER(entity_type, EntityClass) \ | ||||||
|  |   bool InitialStateIterator::on_##entity_type(EntityClass *entity) { \ | ||||||
|  |     return this->client_->send_##entity_type##_state(entity); \ | ||||||
|  |   } | ||||||
|  | // clang-format on | ||||||
|  |  | ||||||
| class InitialStateIterator : public ComponentIterator { | class InitialStateIterator : public ComponentIterator { | ||||||
|  public: |  public: | ||||||
|   InitialStateIterator(APIConnection *client); |   InitialStateIterator(APIConnection *client); | ||||||
| #ifdef USE_BINARY_SENSOR | #ifdef USE_BINARY_SENSOR | ||||||
|   bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) override; |   bool on_binary_sensor(binary_sensor::BinarySensor *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_COVER | #ifdef USE_COVER | ||||||
|   bool on_cover(cover::Cover *cover) override; |   bool on_cover(cover::Cover *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_FAN | #ifdef USE_FAN | ||||||
|   bool on_fan(fan::Fan *fan) override; |   bool on_fan(fan::Fan *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LIGHT | #ifdef USE_LIGHT | ||||||
|   bool on_light(light::LightState *light) override; |   bool on_light(light::LightState *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SENSOR | #ifdef USE_SENSOR | ||||||
|   bool on_sensor(sensor::Sensor *sensor) override; |   bool on_sensor(sensor::Sensor *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SWITCH | #ifdef USE_SWITCH | ||||||
|   bool on_switch(switch_::Switch *a_switch) override; |   bool on_switch(switch_::Switch *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_BUTTON | #ifdef USE_BUTTON | ||||||
|   bool on_button(button::Button *button) override { return true; }; |   bool on_button(button::Button *button) override { return true; }; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT_SENSOR | #ifdef USE_TEXT_SENSOR | ||||||
|   bool on_text_sensor(text_sensor::TextSensor *text_sensor) override; |   bool on_text_sensor(text_sensor::TextSensor *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_CLIMATE | #ifdef USE_CLIMATE | ||||||
|   bool on_climate(climate::Climate *climate) override; |   bool on_climate(climate::Climate *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_NUMBER | #ifdef USE_NUMBER | ||||||
|   bool on_number(number::Number *number) override; |   bool on_number(number::Number *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATE | #ifdef USE_DATETIME_DATE | ||||||
|   bool on_date(datetime::DateEntity *date) override; |   bool on_date(datetime::DateEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_TIME | #ifdef USE_DATETIME_TIME | ||||||
|   bool on_time(datetime::TimeEntity *time) override; |   bool on_time(datetime::TimeEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATETIME | #ifdef USE_DATETIME_DATETIME | ||||||
|   bool on_datetime(datetime::DateTimeEntity *datetime) override; |   bool on_datetime(datetime::DateTimeEntity *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT | #ifdef USE_TEXT | ||||||
|   bool on_text(text::Text *text) override; |   bool on_text(text::Text *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_SELECT | #ifdef USE_SELECT | ||||||
|   bool on_select(select::Select *select) override; |   bool on_select(select::Select *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_LOCK | #ifdef USE_LOCK | ||||||
|   bool on_lock(lock::Lock *a_lock) override; |   bool on_lock(lock::Lock *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_VALVE | #ifdef USE_VALVE | ||||||
|   bool on_valve(valve::Valve *valve) override; |   bool on_valve(valve::Valve *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_MEDIA_PLAYER | #ifdef USE_MEDIA_PLAYER | ||||||
|   bool on_media_player(media_player::MediaPlayer *media_player) override; |   bool on_media_player(media_player::MediaPlayer *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_ALARM_CONTROL_PANEL | #ifdef USE_ALARM_CONTROL_PANEL | ||||||
|   bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override; |   bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *entity) override; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_EVENT | #ifdef USE_EVENT | ||||||
|   bool on_event(event::Event *event) override { return true; }; |   bool on_event(event::Event *event) override { return true; }; | ||||||
| #endif | #endif | ||||||
| #ifdef USE_UPDATE | #ifdef USE_UPDATE | ||||||
|   bool on_update(update::UpdateEntity *update) override; |   bool on_update(update::UpdateEntity *entity) override; | ||||||
| #endif | #endif | ||||||
|   bool completed() { return this->state_ == IteratorState::NONE; } |   bool completed() { return this->state_ == IteratorState::NONE; } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user