Skip to content

Commit

Permalink
Add customData config to Home Assistant notification. Resolves #375
Browse files Browse the repository at this point in the history
  • Loading branch information
claabs committed Feb 17, 2024
1 parent 5e62866 commit 2734e6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/common/config/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ export class HomeassistantConfig extends NotifierConfig {
@IsString()
notifyservice: string;

/**
* A key-value pair object to additionally pass into the service's `data` object
* @example { "parse_mode": "html" }
* @env HOMEASSISTANT_CUSTOM_DATA (stringified JSON)
*/
@IsObject()
@IsOptional()
customData: Record<string, boolean | number | string> | undefined;

/**
* @ignore
*/
Expand Down Expand Up @@ -1088,6 +1097,7 @@ export class AppConfig {
HOMEASSISTANT_INSTANCE,
HOMEASSISTANT_LONG_LIVED_ACCESS_TOKEN,
HOMEASSISTANT_NOTIFYSERVICE,
HOMEASSISTANT_CUSTOM_DATA,
} = process.env;
if (
HOMEASSISTANT_INSTANCE &&
Expand All @@ -1098,6 +1108,9 @@ export class AppConfig {
homeassistant.instance = HOMEASSISTANT_INSTANCE;
homeassistant.token = HOMEASSISTANT_LONG_LIVED_ACCESS_TOKEN;
homeassistant.notifyservice = HOMEASSISTANT_NOTIFYSERVICE;
homeassistant.customData = HOMEASSISTANT_CUSTOM_DATA
? JSON.parse(HOMEASSISTANT_CUSTOM_DATA)
: undefined;
if (!this.notifiers) {
this.notifiers = [];
}
Expand Down
1 change: 1 addition & 0 deletions src/notifiers/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class HomeassistantNotifier extends NotifierService {
data: {
url,
clickAction: url,
...(this.config.customData ?? {}),
},
},
{
Expand Down

0 comments on commit 2734e6b

Please sign in to comment.