void ha_event_cb(ha_event_t event, homeAssisatnt_device_t* ha_dev)
{
switch (event)
{
case HA_EVENT_MQTT_CONNECED:
HA_LOG_I("<<<<<<<<<< HA_EVENT_MQTT_CONNECED\r\n");
//一定要加static
static ha_sw_entity_t entity_sw1 = {
.name = "开关1",
.icon = "mdi:power",
.unique_id = "ai-wb2_sw1",
};
homeAssistant_device_add_entity(CONFIG_HA_ENTITY_SWITCH, &entity_sw1);
homeAssistant_device_send_status(HOMEASSISTANT_STATUS_ONLINE);
homeAssistant_device_send_entity_state(CONFIG_HA_ENTITY_SWITCH, &entity_sw1, 0);
break;
case HA_EVENT_MQTT_DISCONNECT:
HA_LOG_I("<<<<<<<<<< HA_EVENT_MQTT_DISCONNECT\r\n");
break;
case HA_EVENT_MQTT_COMMAND_SWITCH:
HA_LOG_I("<<<<<<<<<< HA_EVENT_MQTT_COMMAND_SWITCH\r\n");
// LOG_I("switch addr =%p", ha_dev->entity_switch->command_switch);
HA_LOG_I(" switch %s is %s\r\n", ha_dev->entity_switch->command_switch->name, ha_dev->entity_switch->command_switch->switch_state?"true":"flase");
int ret = homeAssistant_device_send_entity_state(CONFIG_HA_ENTITY_SWITCH, ha_dev->entity_switch->command_switch, ha_dev->entity_switch->command_switch->switch_state);
if (ret!=-1)HA_LOG_I("%s send entity suceess,state=%s\r\n", ha_dev->entity_switch->command_switch->name, ha_dev->entity_switch->command_switch->switch_state?"true":"flase");
break;
default:
break;
}
}