Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/ble_client_hid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


DEPENDENCIES = ['ble_client']
AUTO_LOAD = ["sensor", "text_sensor"]
CODE_OWNERS=["@fsievers22"]

MULTI_CONF=3
Expand Down Expand Up @@ -52,4 +53,4 @@ async def register_battery_sensor(var, config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await ble_client.register_ble_node(var, config)
await ble_client.register_ble_node(var, config)
4 changes: 3 additions & 1 deletion components/ble_client_hid/ble_client_hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ void BLEClientHID::send_input_report_event(esp_ble_gattc_cb_param_t *p_data){
} else {
usage = std::to_string(value.usage.page) + "_" + std::to_string(value.usage.usage);
}
#ifdef USE_API
this->fire_homeassistant_event("esphome.hid_events", {{"usage", usage}, {"value", std::to_string(value.value)}});
ESP_LOGD(TAG, "Send HID event to HomeAssistant: usage: %s, value: %d", usage.c_str(), value.value);
#endif
if(this->last_event_usage_text_sensor != nullptr){
this->last_event_usage_text_sensor->publish_state(usage);
}
if(this->last_event_value_sensor != nullptr){
this->last_event_value_sensor->publish_state(value.value);
}
ESP_LOGD(TAG, "Send HID event to HomeAssistant: usage: %s, value: %d", usage.c_str(), value.value);
}

delete[] data;
Expand Down
8 changes: 8 additions & 0 deletions components/ble_client_hid/ble_client_hid.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <map>
#include "esphome/core/component.h"
#include "esphome/components/ble_client/ble_client.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/text_sensor/text_sensor.h"
#ifdef USE_API
#include "esphome/components/api/custom_api_device.h"
#endif
#include "hid_parser.h"

#ifdef USE_ESP32
Expand Down Expand Up @@ -53,7 +57,11 @@ class GATTReadData {
uint16_t handle_;
};

#ifdef USE_API
class BLEClientHID : public Component, public api::CustomAPIDevice, public ble_client::BLEClientNode {
#else
class BLEClientHID : public Component, public ble_client::BLEClientNode {
#endif
public:
void loop() override;
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
Expand Down