Skip to content

Commit

Permalink
Fix conversion toLocaleTimeString
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Nov 29, 2024
1 parent 8a4a974 commit 22b5d39
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dist/automations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
/**
* This file contains the class AutomationsExtension and its definitions.
*
Expand Down Expand Up @@ -179,7 +180,9 @@ class AutomationsExtension {
const times = suncalc.getTimes(new Date(), timeTrigger.latitude, timeTrigger.longitude, timeTrigger.elevation ? timeTrigger.elevation : 0);
this.logger.debug(`[Automations] Sunrise at ${times[ConfigSunCalc.SUNRISE].toLocaleTimeString()} sunset at ${times[ConfigSunCalc.SUNSET].toLocaleTimeString()} for latitude:${timeTrigger.latitude} longitude:${timeTrigger.longitude} elevation:${timeTrigger.elevation ? timeTrigger.elevation : 0}`);
this.log.debug(`[Automations] For latitude:${timeTrigger.latitude} longitude:${timeTrigger.longitude} elevation:${timeTrigger.elevation ? timeTrigger.elevation : 0} suncalc are:\n`, times);
const time = times[trigger.time].toLocaleTimeString();
const options = { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' };
const time = times[trigger.time].toLocaleTimeString('en-GB', options);
this.log.debug(`[Automations] Registering time automation [${key}] trigger: ${time}`);
if (!this.timeAutomations[time])
this.timeAutomations[time] = [];
this.timeAutomations[time].push({ name: key, execute_once: configAutomation.execute_once, trigger: timeTrigger, action: actions, condition: conditions });
Expand Down
2 changes: 1 addition & 1 deletion loadExtension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $jsonPayload | Set-Content -Path $jsonFilePath

# Use the temporary file in the mosquitto_pub command
& 'C:\Program Files\mosquitto\mosquitto_pub' -h localhost -t 'zigbee2mqtt/bridge/request/extension/save' -f $jsonFilePath
#& 'C:\Program Files\mosquitto\mosquitto_pub' -h raspberrypi.local -t 'zigbee2mqtt/bridge/request/extension/save' -f $jsonFilePath
& 'C:\Program Files\mosquitto\mosquitto_pub' -h raspberrypi.local -t 'zigbee2mqtt/bridge/request/extension/save' -f $jsonFilePath

# Optionally, clean up the temporary file after publishing
Remove-Item -Path $jsonFilePath
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zigbee2mqtt-automations",
"version": "1.0.8",
"version": "1.0.9",
"description": "Automations extension for zigbee2mqtt",
"author": "Luligu",
"license": "MIT",
Expand All @@ -15,7 +15,6 @@
"mqtt-accessories",
"zigbee2mqtt",
"zigbee-herdsman",
"zigbee-herdsman",
"zigbee-herdsman-converters",
"frontend",
"automations",
Expand Down
4 changes: 3 additions & 1 deletion src/automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ class AutomationsExtension {
const times = suncalc.getTimes(new Date(), timeTrigger.latitude, timeTrigger.longitude, timeTrigger.elevation ? timeTrigger.elevation : 0) as object;
this.logger.debug(`[Automations] Sunrise at ${times[ConfigSunCalc.SUNRISE].toLocaleTimeString()} sunset at ${times[ConfigSunCalc.SUNSET].toLocaleTimeString()} for latitude:${timeTrigger.latitude} longitude:${timeTrigger.longitude} elevation:${timeTrigger.elevation ? timeTrigger.elevation : 0}`);
this.log.debug(`[Automations] For latitude:${timeTrigger.latitude} longitude:${timeTrigger.longitude} elevation:${timeTrigger.elevation ? timeTrigger.elevation : 0} suncalc are:\n`, times);
const time = times[trigger.time].toLocaleTimeString();
const options = { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' };
const time = times[trigger.time].toLocaleTimeString('en-GB', options);
this.log.debug(`[Automations] Registering time automation [${key}] trigger: ${time}`);
if (!this.timeAutomations[time])
this.timeAutomations[time] = [];
this.timeAutomations[time].push({ name: key, execute_once: configAutomation.execute_once, trigger: timeTrigger, action: actions, condition: conditions });
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": false,
"noImplicitUseStrict": true,
"ignoreDeprecations": "5.0",
"types": [
"node"
Expand Down

0 comments on commit 22b5d39

Please sign in to comment.