-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,687 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#define MAX_LEN 32 | ||
#define MAX_ENTITIES (3 * 9 + 16 * 7 + 32) | ||
|
||
typedef enum | ||
{ | ||
ha_unused = 0, | ||
/* https://www.home-assistant.io/integrations/text.mqtt/ */ | ||
ha_text, | ||
/* https://www.home-assistant.io/integrations/sensor.mqtt/ */ | ||
ha_sensor, | ||
/* https://www.home-assistant.io/integrations/number.mqtt/ */ | ||
ha_number, | ||
/* https://www.home-assistant.io/integrations/button.mqtt/ */ | ||
ha_button, | ||
/* https://www.home-assistant.io/integrations/select.mqtt/ */ | ||
ha_select, | ||
/* https://www.home-assistant.io/integrations/binary_sensor.mqtt/ */ | ||
ha_binary_sensor, | ||
/* https://www.home-assistant.io/integrations/ha_light.mqtt/ */ | ||
ha_light | ||
} t_ha_device_type; | ||
|
||
typedef struct s_ha_entity t_ha_entity; | ||
|
||
struct s_ha_entity | ||
{ | ||
t_ha_device_type type; | ||
|
||
const char *name; | ||
const char *id; | ||
|
||
/* used by: sensor */ | ||
const char *unit_of_meas; | ||
/* used by: sensor */ | ||
const char *val_tpl; | ||
/* used by: sensor */ | ||
const char *dev_class; | ||
/* used by: sensor */ | ||
const char *state_class; | ||
/* used by: button, number, text */ | ||
const char *cmd_t; | ||
/* used by: sensor, binary_sensor, number, text */ | ||
const char *stat_t; | ||
/* used by: light */ | ||
const char *rgb_t; | ||
const char *rgbw_t; | ||
/* used by: switch, comma separated */ | ||
const char *options; | ||
/* used by: number */ | ||
float min; | ||
/* used by: number */ | ||
float max; | ||
/* used by: number */ | ||
const char *mode; | ||
/* icon */ | ||
const char *ic; | ||
/* entity_category */ | ||
const char *ent_cat; | ||
|
||
/* used by: light */ | ||
const char *fx_cmd_t; | ||
/* used by: light */ | ||
const char *fx_stat_t; | ||
/* used by: light, comma separated */ | ||
const char *fx_list; | ||
|
||
/* alternative client name */ | ||
const char *alt_name; | ||
|
||
void (*received)(const t_ha_entity *, void *, const char *); | ||
void *received_ctx; | ||
void (*rgb_received)(const t_ha_entity *, void *, const char *); | ||
void *rgb_received_ctx; | ||
void (*fx_received)(const t_ha_entity *, void *, const char *); | ||
void *fx_received_ctx; | ||
void (*transmit)(const t_ha_entity *, void *); | ||
void *transmit_ctx; | ||
}; | ||
|
||
typedef struct | ||
{ | ||
char name[MAX_LEN]; | ||
char id[MAX_LEN]; | ||
char cu[MAX_LEN]; | ||
char mf[MAX_LEN]; | ||
char mdl[MAX_LEN]; | ||
char sw[MAX_LEN]; | ||
t_ha_entity entities[MAX_ENTITIES]; | ||
int entitiy_count; | ||
} t_ha_info; | ||
|
||
void ha_setup(); | ||
void ha_connected(); | ||
bool ha_loop(); | ||
void ha_transmit_all(); | ||
void ha_publish(); | ||
void ha_add(t_ha_entity *entity); | ||
void ha_addmqtt(char *json_str, const char *name, const char *value, t_ha_entity *entity, bool last); | ||
void ha_received(char *topic, const char *payload); | ||
void ha_transmit(const t_ha_entity *entity, const char *value); | ||
void ha_transmit_topic(const char *stat_t, const char *value); | ||
int ha_parse_index(const char *options, const char *message); | ||
void ha_get_index(const char *options, int index, char *text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __MACROS_H__ | ||
#define __MACROS_H__ | ||
|
||
// #define min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) | ||
// #define max(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) | ||
#define coerce(val, min, max) \ | ||
do \ | ||
{ \ | ||
if ((val) > (max)) \ | ||
{ \ | ||
val = max; \ | ||
} \ | ||
else if ((val) < (min)) \ | ||
{ \ | ||
val = min; \ | ||
} \ | ||
} while (0) | ||
#define xstr(s) str(s) | ||
#define str(s) #s | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "error.h" | ||
|
||
void mqtt_init(); | ||
error_t mqtt_sendEvent(const char *eventname, const char *content); | ||
bool mqtt_publish(const char *item_topic, const char *content); | ||
bool mqtt_subscribe(const char *item_topic); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.