mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Reduce code duplication in auto-generated API protocol code
This commit is contained in:
		| @@ -620,8 +620,7 @@ void APIServerConnection::on_ping_request(const PingRequest &msg) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| void APIServerConnection::on_device_info_request(const DeviceInfoRequest &msg) { | void APIServerConnection::on_device_info_request(const DeviceInfoRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_connection_setup_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   DeviceInfoResponse ret = this->device_info(msg); |   DeviceInfoResponse ret = this->device_info(msg); | ||||||
| @@ -630,64 +629,38 @@ void APIServerConnection::on_device_info_request(const DeviceInfoRequest &msg) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| void APIServerConnection::on_list_entities_request(const ListEntitiesRequest &msg) { | void APIServerConnection::on_list_entities_request(const ListEntitiesRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->list_entities(msg); |   this->list_entities(msg); | ||||||
| } | } | ||||||
| void APIServerConnection::on_subscribe_states_request(const SubscribeStatesRequest &msg) { | void APIServerConnection::on_subscribe_states_request(const SubscribeStatesRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_states(msg); |   this->subscribe_states(msg); | ||||||
| } | } | ||||||
| void APIServerConnection::on_subscribe_logs_request(const SubscribeLogsRequest &msg) { | void APIServerConnection::on_subscribe_logs_request(const SubscribeLogsRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_logs(msg); |   this->subscribe_logs(msg); | ||||||
| } | } | ||||||
| void APIServerConnection::on_subscribe_homeassistant_services_request( | void APIServerConnection::on_subscribe_homeassistant_services_request( | ||||||
|     const SubscribeHomeassistantServicesRequest &msg) { |     const SubscribeHomeassistantServicesRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_homeassistant_services(msg); |   this->subscribe_homeassistant_services(msg); | ||||||
| } | } | ||||||
| void APIServerConnection::on_subscribe_home_assistant_states_request(const SubscribeHomeAssistantStatesRequest &msg) { | void APIServerConnection::on_subscribe_home_assistant_states_request(const SubscribeHomeAssistantStatesRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_home_assistant_states(msg); |   this->subscribe_home_assistant_states(msg); | ||||||
| } | } | ||||||
| void APIServerConnection::on_get_time_request(const GetTimeRequest &msg) { | void APIServerConnection::on_get_time_request(const GetTimeRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_connection_setup_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   GetTimeResponse ret = this->get_time(msg); |   GetTimeResponse ret = this->get_time(msg); | ||||||
| @@ -696,24 +669,14 @@ void APIServerConnection::on_get_time_request(const GetTimeRequest &msg) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| void APIServerConnection::on_execute_service_request(const ExecuteServiceRequest &msg) { | void APIServerConnection::on_execute_service_request(const ExecuteServiceRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->execute_service(msg); |   this->execute_service(msg); | ||||||
| } | } | ||||||
| #ifdef USE_API_NOISE | #ifdef USE_API_NOISE | ||||||
| void APIServerConnection::on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) { | void APIServerConnection::on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   NoiseEncryptionSetKeyResponse ret = this->noise_encryption_set_key(msg); |   NoiseEncryptionSetKeyResponse ret = this->noise_encryption_set_key(msg); | ||||||
| @@ -724,12 +687,7 @@ void APIServerConnection::on_noise_encryption_set_key_request(const NoiseEncrypt | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BUTTON | #ifdef USE_BUTTON | ||||||
| void APIServerConnection::on_button_command_request(const ButtonCommandRequest &msg) { | void APIServerConnection::on_button_command_request(const ButtonCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->button_command(msg); |   this->button_command(msg); | ||||||
| @@ -737,12 +695,7 @@ void APIServerConnection::on_button_command_request(const ButtonCommandRequest & | |||||||
| #endif | #endif | ||||||
| #ifdef USE_ESP32_CAMERA | #ifdef USE_ESP32_CAMERA | ||||||
| void APIServerConnection::on_camera_image_request(const CameraImageRequest &msg) { | void APIServerConnection::on_camera_image_request(const CameraImageRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->camera_image(msg); |   this->camera_image(msg); | ||||||
| @@ -750,12 +703,7 @@ void APIServerConnection::on_camera_image_request(const CameraImageRequest &msg) | |||||||
| #endif | #endif | ||||||
| #ifdef USE_CLIMATE | #ifdef USE_CLIMATE | ||||||
| void APIServerConnection::on_climate_command_request(const ClimateCommandRequest &msg) { | void APIServerConnection::on_climate_command_request(const ClimateCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->climate_command(msg); |   this->climate_command(msg); | ||||||
| @@ -763,12 +711,7 @@ void APIServerConnection::on_climate_command_request(const ClimateCommandRequest | |||||||
| #endif | #endif | ||||||
| #ifdef USE_COVER | #ifdef USE_COVER | ||||||
| void APIServerConnection::on_cover_command_request(const CoverCommandRequest &msg) { | void APIServerConnection::on_cover_command_request(const CoverCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->cover_command(msg); |   this->cover_command(msg); | ||||||
| @@ -776,12 +719,7 @@ void APIServerConnection::on_cover_command_request(const CoverCommandRequest &ms | |||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATE | #ifdef USE_DATETIME_DATE | ||||||
| void APIServerConnection::on_date_command_request(const DateCommandRequest &msg) { | void APIServerConnection::on_date_command_request(const DateCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->date_command(msg); |   this->date_command(msg); | ||||||
| @@ -789,12 +727,7 @@ void APIServerConnection::on_date_command_request(const DateCommandRequest &msg) | |||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_DATETIME | #ifdef USE_DATETIME_DATETIME | ||||||
| void APIServerConnection::on_date_time_command_request(const DateTimeCommandRequest &msg) { | void APIServerConnection::on_date_time_command_request(const DateTimeCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->datetime_command(msg); |   this->datetime_command(msg); | ||||||
| @@ -802,12 +735,7 @@ void APIServerConnection::on_date_time_command_request(const DateTimeCommandRequ | |||||||
| #endif | #endif | ||||||
| #ifdef USE_FAN | #ifdef USE_FAN | ||||||
| void APIServerConnection::on_fan_command_request(const FanCommandRequest &msg) { | void APIServerConnection::on_fan_command_request(const FanCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->fan_command(msg); |   this->fan_command(msg); | ||||||
| @@ -815,12 +743,7 @@ void APIServerConnection::on_fan_command_request(const FanCommandRequest &msg) { | |||||||
| #endif | #endif | ||||||
| #ifdef USE_LIGHT | #ifdef USE_LIGHT | ||||||
| void APIServerConnection::on_light_command_request(const LightCommandRequest &msg) { | void APIServerConnection::on_light_command_request(const LightCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->light_command(msg); |   this->light_command(msg); | ||||||
| @@ -828,12 +751,7 @@ void APIServerConnection::on_light_command_request(const LightCommandRequest &ms | |||||||
| #endif | #endif | ||||||
| #ifdef USE_LOCK | #ifdef USE_LOCK | ||||||
| void APIServerConnection::on_lock_command_request(const LockCommandRequest &msg) { | void APIServerConnection::on_lock_command_request(const LockCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->lock_command(msg); |   this->lock_command(msg); | ||||||
| @@ -841,12 +759,7 @@ void APIServerConnection::on_lock_command_request(const LockCommandRequest &msg) | |||||||
| #endif | #endif | ||||||
| #ifdef USE_MEDIA_PLAYER | #ifdef USE_MEDIA_PLAYER | ||||||
| void APIServerConnection::on_media_player_command_request(const MediaPlayerCommandRequest &msg) { | void APIServerConnection::on_media_player_command_request(const MediaPlayerCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->media_player_command(msg); |   this->media_player_command(msg); | ||||||
| @@ -854,12 +767,7 @@ void APIServerConnection::on_media_player_command_request(const MediaPlayerComma | |||||||
| #endif | #endif | ||||||
| #ifdef USE_NUMBER | #ifdef USE_NUMBER | ||||||
| void APIServerConnection::on_number_command_request(const NumberCommandRequest &msg) { | void APIServerConnection::on_number_command_request(const NumberCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->number_command(msg); |   this->number_command(msg); | ||||||
| @@ -867,12 +775,7 @@ void APIServerConnection::on_number_command_request(const NumberCommandRequest & | |||||||
| #endif | #endif | ||||||
| #ifdef USE_SELECT | #ifdef USE_SELECT | ||||||
| void APIServerConnection::on_select_command_request(const SelectCommandRequest &msg) { | void APIServerConnection::on_select_command_request(const SelectCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->select_command(msg); |   this->select_command(msg); | ||||||
| @@ -880,12 +783,7 @@ void APIServerConnection::on_select_command_request(const SelectCommandRequest & | |||||||
| #endif | #endif | ||||||
| #ifdef USE_SIREN | #ifdef USE_SIREN | ||||||
| void APIServerConnection::on_siren_command_request(const SirenCommandRequest &msg) { | void APIServerConnection::on_siren_command_request(const SirenCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->siren_command(msg); |   this->siren_command(msg); | ||||||
| @@ -893,12 +791,7 @@ void APIServerConnection::on_siren_command_request(const SirenCommandRequest &ms | |||||||
| #endif | #endif | ||||||
| #ifdef USE_SWITCH | #ifdef USE_SWITCH | ||||||
| void APIServerConnection::on_switch_command_request(const SwitchCommandRequest &msg) { | void APIServerConnection::on_switch_command_request(const SwitchCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->switch_command(msg); |   this->switch_command(msg); | ||||||
| @@ -906,12 +799,7 @@ void APIServerConnection::on_switch_command_request(const SwitchCommandRequest & | |||||||
| #endif | #endif | ||||||
| #ifdef USE_TEXT | #ifdef USE_TEXT | ||||||
| void APIServerConnection::on_text_command_request(const TextCommandRequest &msg) { | void APIServerConnection::on_text_command_request(const TextCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->text_command(msg); |   this->text_command(msg); | ||||||
| @@ -919,12 +807,7 @@ void APIServerConnection::on_text_command_request(const TextCommandRequest &msg) | |||||||
| #endif | #endif | ||||||
| #ifdef USE_DATETIME_TIME | #ifdef USE_DATETIME_TIME | ||||||
| void APIServerConnection::on_time_command_request(const TimeCommandRequest &msg) { | void APIServerConnection::on_time_command_request(const TimeCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->time_command(msg); |   this->time_command(msg); | ||||||
| @@ -932,12 +815,7 @@ void APIServerConnection::on_time_command_request(const TimeCommandRequest &msg) | |||||||
| #endif | #endif | ||||||
| #ifdef USE_UPDATE | #ifdef USE_UPDATE | ||||||
| void APIServerConnection::on_update_command_request(const UpdateCommandRequest &msg) { | void APIServerConnection::on_update_command_request(const UpdateCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->update_command(msg); |   this->update_command(msg); | ||||||
| @@ -945,12 +823,7 @@ void APIServerConnection::on_update_command_request(const UpdateCommandRequest & | |||||||
| #endif | #endif | ||||||
| #ifdef USE_VALVE | #ifdef USE_VALVE | ||||||
| void APIServerConnection::on_valve_command_request(const ValveCommandRequest &msg) { | void APIServerConnection::on_valve_command_request(const ValveCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->valve_command(msg); |   this->valve_command(msg); | ||||||
| @@ -959,12 +832,7 @@ void APIServerConnection::on_valve_command_request(const ValveCommandRequest &ms | |||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_subscribe_bluetooth_le_advertisements_request( | void APIServerConnection::on_subscribe_bluetooth_le_advertisements_request( | ||||||
|     const SubscribeBluetoothLEAdvertisementsRequest &msg) { |     const SubscribeBluetoothLEAdvertisementsRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_bluetooth_le_advertisements(msg); |   this->subscribe_bluetooth_le_advertisements(msg); | ||||||
| @@ -972,12 +840,7 @@ void APIServerConnection::on_subscribe_bluetooth_le_advertisements_request( | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_device_request(const BluetoothDeviceRequest &msg) { | void APIServerConnection::on_bluetooth_device_request(const BluetoothDeviceRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_device_request(msg); |   this->bluetooth_device_request(msg); | ||||||
| @@ -985,12 +848,7 @@ void APIServerConnection::on_bluetooth_device_request(const BluetoothDeviceReque | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_get_services_request(const BluetoothGATTGetServicesRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_get_services_request(const BluetoothGATTGetServicesRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_get_services(msg); |   this->bluetooth_gatt_get_services(msg); | ||||||
| @@ -998,12 +856,7 @@ void APIServerConnection::on_bluetooth_gatt_get_services_request(const Bluetooth | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_read_request(const BluetoothGATTReadRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_read(msg); |   this->bluetooth_gatt_read(msg); | ||||||
| @@ -1011,12 +864,7 @@ void APIServerConnection::on_bluetooth_gatt_read_request(const BluetoothGATTRead | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_write_request(const BluetoothGATTWriteRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_write_request(const BluetoothGATTWriteRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_write(msg); |   this->bluetooth_gatt_write(msg); | ||||||
| @@ -1024,12 +872,7 @@ void APIServerConnection::on_bluetooth_gatt_write_request(const BluetoothGATTWri | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_read_descriptor_request(const BluetoothGATTReadDescriptorRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_read_descriptor_request(const BluetoothGATTReadDescriptorRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_read_descriptor(msg); |   this->bluetooth_gatt_read_descriptor(msg); | ||||||
| @@ -1037,12 +880,7 @@ void APIServerConnection::on_bluetooth_gatt_read_descriptor_request(const Blueto | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_write_descriptor_request(const BluetoothGATTWriteDescriptorRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_write_descriptor_request(const BluetoothGATTWriteDescriptorRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_write_descriptor(msg); |   this->bluetooth_gatt_write_descriptor(msg); | ||||||
| @@ -1050,12 +888,7 @@ void APIServerConnection::on_bluetooth_gatt_write_descriptor_request(const Bluet | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_gatt_notify_request(const BluetoothGATTNotifyRequest &msg) { | void APIServerConnection::on_bluetooth_gatt_notify_request(const BluetoothGATTNotifyRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_gatt_notify(msg); |   this->bluetooth_gatt_notify(msg); | ||||||
| @@ -1064,12 +897,7 @@ void APIServerConnection::on_bluetooth_gatt_notify_request(const BluetoothGATTNo | |||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_subscribe_bluetooth_connections_free_request( | void APIServerConnection::on_subscribe_bluetooth_connections_free_request( | ||||||
|     const SubscribeBluetoothConnectionsFreeRequest &msg) { |     const SubscribeBluetoothConnectionsFreeRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   BluetoothConnectionsFreeResponse ret = this->subscribe_bluetooth_connections_free(msg); |   BluetoothConnectionsFreeResponse ret = this->subscribe_bluetooth_connections_free(msg); | ||||||
| @@ -1081,12 +909,7 @@ void APIServerConnection::on_subscribe_bluetooth_connections_free_request( | |||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_unsubscribe_bluetooth_le_advertisements_request( | void APIServerConnection::on_unsubscribe_bluetooth_le_advertisements_request( | ||||||
|     const UnsubscribeBluetoothLEAdvertisementsRequest &msg) { |     const UnsubscribeBluetoothLEAdvertisementsRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->unsubscribe_bluetooth_le_advertisements(msg); |   this->unsubscribe_bluetooth_le_advertisements(msg); | ||||||
| @@ -1094,12 +917,7 @@ void APIServerConnection::on_unsubscribe_bluetooth_le_advertisements_request( | |||||||
| #endif | #endif | ||||||
| #ifdef USE_BLUETOOTH_PROXY | #ifdef USE_BLUETOOTH_PROXY | ||||||
| void APIServerConnection::on_bluetooth_scanner_set_mode_request(const BluetoothScannerSetModeRequest &msg) { | void APIServerConnection::on_bluetooth_scanner_set_mode_request(const BluetoothScannerSetModeRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->bluetooth_scanner_set_mode(msg); |   this->bluetooth_scanner_set_mode(msg); | ||||||
| @@ -1107,12 +925,7 @@ void APIServerConnection::on_bluetooth_scanner_set_mode_request(const BluetoothS | |||||||
| #endif | #endif | ||||||
| #ifdef USE_VOICE_ASSISTANT | #ifdef USE_VOICE_ASSISTANT | ||||||
| void APIServerConnection::on_subscribe_voice_assistant_request(const SubscribeVoiceAssistantRequest &msg) { | void APIServerConnection::on_subscribe_voice_assistant_request(const SubscribeVoiceAssistantRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->subscribe_voice_assistant(msg); |   this->subscribe_voice_assistant(msg); | ||||||
| @@ -1120,12 +933,7 @@ void APIServerConnection::on_subscribe_voice_assistant_request(const SubscribeVo | |||||||
| #endif | #endif | ||||||
| #ifdef USE_VOICE_ASSISTANT | #ifdef USE_VOICE_ASSISTANT | ||||||
| void APIServerConnection::on_voice_assistant_configuration_request(const VoiceAssistantConfigurationRequest &msg) { | void APIServerConnection::on_voice_assistant_configuration_request(const VoiceAssistantConfigurationRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   VoiceAssistantConfigurationResponse ret = this->voice_assistant_get_configuration(msg); |   VoiceAssistantConfigurationResponse ret = this->voice_assistant_get_configuration(msg); | ||||||
| @@ -1136,12 +944,7 @@ void APIServerConnection::on_voice_assistant_configuration_request(const VoiceAs | |||||||
| #endif | #endif | ||||||
| #ifdef USE_VOICE_ASSISTANT | #ifdef USE_VOICE_ASSISTANT | ||||||
| void APIServerConnection::on_voice_assistant_set_configuration(const VoiceAssistantSetConfiguration &msg) { | void APIServerConnection::on_voice_assistant_set_configuration(const VoiceAssistantSetConfiguration &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->voice_assistant_set_configuration(msg); |   this->voice_assistant_set_configuration(msg); | ||||||
| @@ -1149,12 +952,7 @@ void APIServerConnection::on_voice_assistant_set_configuration(const VoiceAssist | |||||||
| #endif | #endif | ||||||
| #ifdef USE_ALARM_CONTROL_PANEL | #ifdef USE_ALARM_CONTROL_PANEL | ||||||
| void APIServerConnection::on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg) { | void APIServerConnection::on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg) { | ||||||
|   if (!this->is_connection_setup()) { |   if (!this->check_authenticated_()) { | ||||||
|     this->on_no_setup_connection(); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   if (!this->is_authenticated()) { |  | ||||||
|     this->on_unauthenticated_access(); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->alarm_control_panel_command(msg); |   this->alarm_control_panel_command(msg); | ||||||
|   | |||||||
| @@ -17,6 +17,26 @@ class APIServerConnectionBase : public ProtoService { | |||||||
|  public: |  public: | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |  protected: | ||||||
|  |   bool check_connection_setup_() { | ||||||
|  |     if (!this->is_connection_setup()) { | ||||||
|  |       this->on_no_setup_connection(); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
|  |   bool check_authenticated_() { | ||||||
|  |     if (!this->check_connection_setup_()) { | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     if (!this->is_authenticated()) { | ||||||
|  |       this->on_unauthenticated_access(); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |  public: | ||||||
|   template<typename T> bool send_message(const T &msg) { |   template<typename T> bool send_message(const T &msg) { | ||||||
| #ifdef HAS_PROTO_MESSAGE_DUMP | #ifdef HAS_PROTO_MESSAGE_DUMP | ||||||
|     this->log_send_message_(T::message_name(), msg.dump()); |     this->log_send_message_(T::message_name(), msg.dump()); | ||||||
|   | |||||||
| @@ -1353,6 +1353,27 @@ def main() -> None: | |||||||
|     hpp += " public:\n" |     hpp += " public:\n" | ||||||
|     hpp += "#endif\n\n" |     hpp += "#endif\n\n" | ||||||
|  |  | ||||||
|  |     # Add authentication check helper methods | ||||||
|  |     hpp += " protected:\n" | ||||||
|  |     hpp += "  bool check_connection_setup_() {\n" | ||||||
|  |     hpp += "    if (!this->is_connection_setup()) {\n" | ||||||
|  |     hpp += "      this->on_no_setup_connection();\n" | ||||||
|  |     hpp += "      return false;\n" | ||||||
|  |     hpp += "    }\n" | ||||||
|  |     hpp += "    return true;\n" | ||||||
|  |     hpp += "  }\n" | ||||||
|  |     hpp += "  bool check_authenticated_() {\n" | ||||||
|  |     hpp += "    if (!this->check_connection_setup_()) {\n" | ||||||
|  |     hpp += "      return false;\n" | ||||||
|  |     hpp += "    }\n" | ||||||
|  |     hpp += "    if (!this->is_authenticated()) {\n" | ||||||
|  |     hpp += "      this->on_unauthenticated_access();\n" | ||||||
|  |     hpp += "      return false;\n" | ||||||
|  |     hpp += "    }\n" | ||||||
|  |     hpp += "    return true;\n" | ||||||
|  |     hpp += "  }\n" | ||||||
|  |     hpp += " public:\n\n" | ||||||
|  |  | ||||||
|     # Add generic send_message method |     # Add generic send_message method | ||||||
|     hpp += "  template<typename T>\n" |     hpp += "  template<typename T>\n" | ||||||
|     hpp += "  bool send_message(const T &msg) {\n" |     hpp += "  bool send_message(const T &msg) {\n" | ||||||
| @@ -1426,14 +1447,12 @@ def main() -> None: | |||||||
|         hpp += f"  virtual {ret} {func}(const {inp} &msg) = 0;\n" |         hpp += f"  virtual {ret} {func}(const {inp} &msg) = 0;\n" | ||||||
|         cpp += f"void {class_name}::{on_func}(const {inp} &msg) {{\n" |         cpp += f"void {class_name}::{on_func}(const {inp} &msg) {{\n" | ||||||
|         body = "" |         body = "" | ||||||
|         if needs_conn: |         if needs_auth: | ||||||
|             body += "if (!this->is_connection_setup()) {\n" |             body += "if (!this->check_authenticated_()) {\n" | ||||||
|             body += "  this->on_no_setup_connection();\n" |  | ||||||
|             body += "  return;\n" |             body += "  return;\n" | ||||||
|             body += "}\n" |             body += "}\n" | ||||||
|         if needs_auth: |         elif needs_conn: | ||||||
|             body += "if (!this->is_authenticated()) {\n" |             body += "if (!this->check_connection_setup_()) {\n" | ||||||
|             body += "  this->on_unauthenticated_access();\n" |  | ||||||
|             body += "  return;\n" |             body += "  return;\n" | ||||||
|             body += "}\n" |             body += "}\n" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user