homebridge-alexa 0.6.9-beta.8 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@ jobs:
52
52
  persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
53
53
  fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
54
54
 
55
- - uses: actions/setup-node@v3
55
+ - uses: actions/setup-node@v4
56
56
  with:
57
57
  node-version: lts/*
58
58
 
@@ -64,13 +64,14 @@ jobs:
64
64
  - name: Create Table of Contents
65
65
  run: |
66
66
  npm run-script document
67
+ rm gh-md-toc
67
68
 
68
69
  - name: Commit files
69
70
  run: |
70
71
  git config --local user.email "github-actions[bot]@users.noreply.github.com"
71
72
  git config --local user.name "github-actions[bot]"
72
73
  git add *
73
- git commit -a -m "Update TOC"
74
+ git commit -a -m "Update TOC" || true
74
75
 
75
76
  - name: Push changes
76
77
  uses: ad-m/github-push-action@master
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 0.6.9 (2023-03-30)
6
+
7
+ ## [Version 0.6.9](https://github.com/northernman54/homebridge-alexa/compare/v0.6.8...v0.6.9)
8
+
9
+ #### Changes
10
+
11
+ - Enables Thermostat type accessory to `Turn Off` and `Turn On` #605 ( Tks @banboobee ). To preserve existing functionality the inital / default behaviour for the `Turn on Thermostat` command is to return an error message `That command does not work on device` unless the new optional config setting `Thermostat Turn On Behaviour` is set.
12
+ - Minor style updates to Config Menu
13
+ - Updates to package dependencies
14
+
5
15
  ## 0.6.8 (2023-12-13)
6
16
 
7
17
  ## [Version 0.6.8](https://github.com/northernman54/homebridge-alexa/compare/v0.6.7...v0.6.8)
package/Installation.md CHANGED
@@ -2,11 +2,44 @@ Installation and Configuration of Homebridge Alexa
2
2
  ==================================================
3
3
 
4
4
  <!--ts-->
5
-
6
-
7
- <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
8
- <!-- Added by: runner, at: Mon Mar 18 13:33:40 UTC 2024 -->
9
-
5
+ * [Installation and Configuration of Homebridge Alexa](#installation-and-configuration-of-homebridge-alexa)
6
+ * [Setup Instructions](#setup-instructions)
7
+ * [Create Homebridge-Alexa Cloud Services Account](#create-homebridge-alexa-cloud-services-account)
8
+ * [Install and Configure the Plugin](#install-and-configure-the-plugin)
9
+ * [Installation in Homebridge UI](#installation-in-homebridge-ui)
10
+ * [Configuration in Homebridge UI](#configuration-in-homebridge-ui)
11
+ * [Enabling and linking the Homebridge Smart Home Skill](#enabling-and-linking-the-homebridge-smart-home-skill)
12
+ * [Viewing Account Status](#viewing-account-status)
13
+ * [Advanced Setup Instructions, including advanced configuration options](#advanced-setup-instructions-including-advanced-configuration-options)
14
+ * [Prepare Homebridge for plugin installation](#prepare-homebridge-for-plugin-installation)
15
+ * [Install Plugin](#install-plugin)
16
+ * [Create homebridge-alexa account](#create-homebridge-alexa-account)
17
+ * [HomeBridge-alexa plugin configuration](#homebridge-alexa-plugin-configuration)
18
+ * [Required Settings](#required-settings)
19
+ * [Optional Settings](#optional-settings)
20
+ * [debug](#debug)
21
+ * [pin](#pin)
22
+ * [routines](#routines)
23
+ * [deviceList &amp; deviceListHandling - Filtering of devices by name, either allow or allow](#devicelist--devicelisthandling---filtering-of-devices-by-name-either-allow-or-allow)
24
+ * [Advanced Settings](#advanced-settings)
25
+ * [CloudTransport - Cloud Server Connection Transport](#cloudtransport---cloud-server-connection-transport)
26
+ * [keepalive - Cloud Server Connection Keepalive](#keepalive---cloud-server-connection-keepalive)
27
+ * [refresh - Accessory Cache Refresh Interval](#refresh---accessory-cache-refresh-interval)
28
+ * [filter - Homebridge Instance Filter](#filter---homebridge-instance-filter)
29
+ * [mergeServiceName - Alternate device naming](#mergeservicename---alternate-device-naming)
30
+ * [thermostatTurnOn - Thermostat Turn On Behaviour](#thermostatturnon---thermostat-turn-on-behaviour)
31
+ * [blind](#blind)
32
+ * [door](#door)
33
+ * [Speaker Settings](#speaker-settings)
34
+ * [speakers](#speakers)
35
+ * [Combine Accessories](#combine-accessories)
36
+ * [combine](#combine)
37
+ * [Inputs](#inputs)
38
+ * [Apple TV](#apple-tv)
39
+ * [Yamaha Spotify Controls](#yamaha-spotify-controls)
40
+ * [Initial Testing and confirming configuration](#initial-testing-and-confirming-configuration)
41
+ * [Enable Homebridge smarthome skill and link accounts](#enable-homebridge-smarthome-skill-and-link-accounts)
42
+ * [Discover Devices](#discover-devices)
10
43
  <!--te-->
11
44
 
12
45
  # Setup Instructions
@@ -286,6 +319,25 @@ sudo npm install -g homebridge-alexa
286
319
  ],
287
320
  ```
288
321
 
322
+ #### thermostatTurnOn - Thermostat Turn On Behaviour
323
+ - Set Thermostat `Turn On` Behaviour to either Heat, Cool or Auto when Alexa is asked to turn on a Thermostat. Defaults to `That command does not work on device`.
324
+
325
+ Heat - 1
326
+ Cool - 2
327
+ Auto - 3
328
+
329
+ ```
330
+ "platforms": [
331
+ {
332
+ "platform": "Alexa",
333
+ "name": "Alexa",
334
+ "username": "....",
335
+ "password": "....",
336
+ "thermostatTurnOn": 2
337
+ }
338
+ ],
339
+ ```
340
+
289
341
  #### blind
290
342
  - Enables natural wording for opening and closing blinds, and window coverings. Not supported in all countries. Defaults to false
291
343
 
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![NPM Downloads](https://img.shields.io/npm/dm/homebridge-alexa.svg?style=flat)](https://npmjs.org/package/homebridge-alexa)
4
4
 
5
- <p align="center">
6
- <img src="docs/echo_5th.jpg" height="200"><img src="docs/homebridge.png" height="200">
7
- </p>
5
+ <h1><p align="center">
6
+ <img src="docs/README_Image.001.jpeg" width="80%" style="vertical-align:middle">
7
+ </p></h1>
8
8
 
9
- Enable Amazon Alexa to control your homebridge smart home devices and accessories. Please note, that this does **NOT** bring Alexa enabled devices into homebridge, for this please try [homebridge-alexa-smarthome](https://github.com/joeyhage/homebridge-alexa-smarthome). Full support for all Amazon Alexa devices, including the echo 2nd Generation and software based solutions. Uses an Amazon smart home skill based approach for integration between HomeBridge and Amazon Alexa.
9
+ Enable Amazon Alexa to control your homebridge smart home devices and accessories. Please note, that this does **NOT** bring Alexa enabled devices into homebridge, for this please try [homebridge-alexa-smarthome](https://github.com/joeyhage/homebridge-alexa-smarthome).
10
10
 
11
11
  # Note to users of the service
12
12
 
@@ -37,11 +37,52 @@ Country availability - The plugin is available in these countries, English (AU),
37
37
 
38
38
  # Table of Contents
39
39
  <!--ts-->
40
-
41
-
42
- <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
43
- <!-- Added by: runner, at: Mon Mar 18 13:33:39 UTC 2024 -->
44
-
40
+ * [Note to users of the service](#note-to-users-of-the-service)
41
+ * [New Users](#new-users)
42
+ * [Availability](#availability)
43
+ * [Features](#features)
44
+ * [Table of Contents](#table-of-contents)
45
+ * [Supported devices](#supported-devices)
46
+ * [HomeKit/Homebridge Devices supported](#homekithomebridge-devices-supported)
47
+ * [Native Support](#native-support)
48
+ * [Supported as Other Types](#supported-as-other-types)
49
+ * [Non-Homebridge Devices](#non-homebridge-devices)
50
+ * [Unsupported device types](#unsupported-device-types)
51
+ * [Alexa Voice Commands](#alexa-voice-commands)
52
+ * [Setup](#setup)
53
+ * [Light bulbs / Switches / Dimmer Switches](#light-bulbs--switches--dimmer-switches)
54
+ * [Color lights](#color-lights)
55
+ * [Color temperature](#color-temperature)
56
+ * [Color Temperatures](#color-temperatures)
57
+ * [Garage door, Blinds and Window Coverings](#garage-door-blinds-and-window-coverings)
58
+ * [Garage Door With door = false](#garage-door-with-door--false)
59
+ * [Window coverings / blinds With blind = false](#window-coverings--blinds-with-blind--false)
60
+ * [Garage Door With blind = true ( Not supported in all countries )](#garage-door-with-blind--true--not-supported-in-all-countries-)
61
+ * [Window coverings / blinds With blind = true ( Not supported in all countries )](#window-coverings--blinds-with-blind--true--not-supported-in-all-countries-)
62
+ * [Thermostat's and Heater / Cooler's](#thermostats-and-heater--coolers)
63
+ * [For Thermostat's only](#for-thermostats-only)
64
+ * [Lock / Unlock Doors](#lock--unlock-doors)
65
+ * [Temperature sensors](#temperature-sensors)
66
+ * [AppleTV ( homebridge-apple-tv or homebridge-apple-tv-remote )](#appletv--homebridge-apple-tv-or-homebridge-apple-tv-remote-)
67
+ * [HomeKit Television](#homekit-television)
68
+ * [HomeKit Television - Tested plugins](#homekit-television---tested-plugins)
69
+ * [Television Inputs and Channels](#television-inputs-and-channels)
70
+ * [Speakers](#speakers)
71
+ * [Bose SoundLink - Change preset](#bose-soundlink---change-preset)
72
+ * [Yamaha Receiver/Spotify control](#yamaha-receiverspotify-control)
73
+ * [Contact and Motion Sensors](#contact-and-motion-sensors)
74
+ * [Door bell devices](#door-bell-devices)
75
+ * [Installation of homebridge-alexa](#installation-of-homebridge-alexa)
76
+ * [Service Availability and Issues](#service-availability-and-issues)
77
+ * [Homebridge cloud service monitoring ( homebridge.ca )](#homebridge-cloud-service-monitoring--homebridgeca-)
78
+ * [Raising Issues and Troubleshooting](#raising-issues-and-troubleshooting)
79
+ * [Troubleshooting](#troubleshooting)
80
+ * [Known Issues](#known-issues)
81
+ * [Discord Channel](#discord-channel)
82
+ * [Debug logs](#debug-logs)
83
+ * [Homebridge Accessory Dump](#homebridge-accessory-dump)
84
+ * [Roadmap](#roadmap)
85
+ * [Credits](#credits)
45
86
  <!--te-->
46
87
 
47
88
  # Supported devices
@@ -173,6 +214,13 @@ See [example](https://github.com/NorthernMan54/homebridge-alexa/wiki/Garage-Door
173
214
  * Alexa, set thermostat to 20
174
215
  * Alexa, set thermostat to heat/cool/automatic/off
175
216
 
217
+ ### For Thermostat's only
218
+
219
+ * Alexa, turn off thermostat
220
+ * Alexa, turn on thermostat
221
+
222
+ The `Turn On` thermostat behaviour is configured in the Optional Setting config menu under `Thermostat Turn On Behaviour`, and unless this is configured `Turn On` is disabled, and alexa will respond with `That command does not work on device`.
223
+
176
224
  Adamo Maisano provided a deeper [comparison](https://github.com/NorthernMan54/homebridge-alexa/wiki/Thermostat-Voice-Control-Comparison) of Thermostat Voice Control [here](https://github.com/NorthernMan54/homebridge-alexa/wiki/Thermostat-Voice-Control-Comparison).
177
225
 
178
226
  ## Lock / Unlock Doors
@@ -1,11 +1,37 @@
1
1
  **Troubleshooting Tips**
2
2
 
3
3
  <!--ts-->
4
-
5
-
6
- <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
7
- <!-- Added by: runner, at: Mon Mar 18 13:33:40 UTC 2024 -->
8
-
4
+ * [Initial Setup](#initial-setup)
5
+ * [[Alexa] ERROR: ( homebridge-alexa) Login to homebridge.ca failed, please validate your credentials in config.json and restart homebridge.](#alexa-error--homebridge-alexa-login-to-homebridgeca-failed-please-validate-your-credentials-in-configjson-and-restart-homebridge)
6
+ * [- Bad login or password in your config.json for <a href="https://www.homebridge.ca" rel="nofollow">https://www.homebridge.ca</a>](https://www.homebridge.ca)
7
+ * [[Alexa] ERROR: ( homebridge-alexa) You have an issue with your installation, please review the README.](#alexa-error--homebridge-alexa-you-have-an-issue-with-your-installation-please-review-the-readme)
8
+ * [- Cloud Server DDOS Protection has blocked your IP address](#--cloud-server-ddos-protection-has-blocked-your-ip-address)
9
+ * [- Multiple copies of homebridge-alexa on your network](#--multiple-copies-of-homebridge-alexa-on-your-network)
10
+ * [- VPN Software interfering with homebridge-alexa to homebridge.ca communications](#--vpn-software-interfering-with-homebridge-alexa-to-homebridgeca-communications)
11
+ * [[Alexa] ERROR: ( homebridge-alexa) Stopping Home Skill connection due to excessive reconnects, please review the README.](#alexa-error--homebridge-alexa-stopping-home-skill-connection-due-to-excessive-reconnects-please-review-the-readme)
12
+ * [[Alexa] WARNING: Duplicate device name xxxxx](#alexa-warning-duplicate-device-name-xxxxx)
13
+ * [Initial Setup Messages from DEBUG mode](#initial-setup-messages-from-debug-mode)
14
+ * [alexaHAP HAP Discover failed ... is not running in insecure mode](#alexahap-hap-discover-failed--is-not-running-in-insecure-mode)
15
+ * [HAP Discover failed ..... error code 470](#hap-discover-failed--error-code-470)
16
+ * [Upgraded from old version and am seeing this error message](#upgraded-from-old-version-and-am-seeing-this-error-message)
17
+ * [[Alexa] ERROR: HAP Discovery failed, please review config](#alexa-error-hap-discovery-failed-please-review-config)
18
+ * [alexaLocal ERROR: connect ECONNREFUSED 35.169.132.61:1883 -&gt; ECONNREFUSED](#alexalocal-error-connect-econnrefused-35169132611883----econnrefused)
19
+ * [alexaLocal error { Error: connect ECONNREFUSED 35.169.132.61:8883](#alexalocal-error--error-connect-econnrefused-35169132618883)
20
+ * [Device Discovery](#device-discovery)
21
+ * [Device discovery fails and the plugin logs show no issues.](#device-discovery-fails-and-the-plugin-logs-show-no-issues)
22
+ * [Device discovery fails, and this message is in the logs ERROR: Empty accessory name, parsing failed.](#device-discovery-fails-and-this-message-is-in-the-logs-error-empty-accessory-name-parsing-failed)
23
+ * [Device discovery fails, and this message is in the logs ERROR: Maximum devices/accessories of 300 exceeded.](#device-discovery-fails-and-this-message-is-in-the-logs-error-maximum-devicesaccessories-of-300-exceeded)
24
+ * [Device discovery fails, and this message is in the logs ERROR: Parsing failed, duplicate endpointID.](#device-discovery-fails-and-this-message-is-in-the-logs-error-parsing-failed-duplicate-endpointid)
25
+ * [After restarting homebridge Alexa can't find devices and needs to discover them again. Or you have duplicate devices in Alexa](#after-restarting-homebridge-alexa-cant-find-devices-and-needs-to-discover-them-again--or-you-have-duplicate-devices-in-alexa)
26
+ * [Controlling devices](#controlling-devices)
27
+ * [[Alexa] PowerController TurnOff 192.168.1.226 51826 undefined Error: Homebridge auth failed, invalid PIN](#alexa-powercontroller-turnoff-1921681226-51826-undefined-error-homebridge-auth-failed-invalid-pin)
28
+ * [Event error messages](#event-error-messages)
29
+ * [[Alexa] WARNING: ( homebridge-alexa) Dropped event message, message rate too high.](#alexa-warning--homebridge-alexa-dropped-event-message-message-rate-too-high)
30
+ * [ERROR: Error: getAccessToken No data Error: XXXXXXXXXX](#error--error-getaccesstoken-no-data-error-xxxxxxxxxx)
31
+ * [ERROR: Error: getAccessToken Token not found](#error--error-getaccesstoken-token-not-found)
32
+ * [Unsuccessful event message ( No event gateway token )](#unsuccessful-event-message--no-event-gateway-token-)
33
+ * [Successful event message being sent to Alexa](#successful-event-message-being-sent-to-alexa)
34
+ * [[Alexa] ERROR: Event gateway token refresh error: 400](#alexa-error--event-gateway-token-refresh-error-400)
9
35
  <!--te-->
10
36
 
11
37
  # Initial Setup
@@ -2,58 +2,68 @@
2
2
  "pluginAlias": "Alexa",
3
3
  "pluginType": "platform",
4
4
  "singular": true,
5
- "headerDisplay": "<h1><p align='center'>Allow your Amazon Alexa to control your homebridge devices</H1></p><h1><p align='center'> <img width='18%' src='https://user-images.githubusercontent.com/19808920/210089307-7622bb91-49d0-4d90-b2c3-31118e1a76c0.png'><b> => </b><img width='20%' src='https://user-images.githubusercontent.com/19808920/210090318-9e8ddc2a-a025-40ac-9718-7b5a2aa9a518.png'></p></h1> <br>To setup the service:<br>1 - First <b>create</b> an account on <a href='https://www.homebridge.ca/'>https://www.homebridge.ca/</a>. <br>2 - Then <b>enter</b> the username and password for your account <b>below</b>. <br>3 - <b>Save</b> the settings and <b>restart</b> homebridge. <br>4 - In the Amazon Alexa Application on your smart phone, <b>search</b> for the Homebridge Skill and enable it. When you enable the skill, it will take you to the <b>https://www.homebridge.ca/</b> website to <b>enable</b> and link the skill to the plugin. <br>5 - You can now ask Alexa to <b>`discover devices`</b> and it should discover your homebridge devices.<br><br>Detailed setup instructions are available <a href='https://github.com/NorthernMan54/homebridge-alexa/blob/master/Installation.md#setup-instructions'>here</a>.",
5
+ "headerDisplay": "<h1><p align='center'>Allow your Amazon Alexa to control your homebridge devices</H1></p><h1><p align='center'><img src='https://raw.githubusercontent.com/NorthernMan54/homebridge-alexa/main/docs/README_Image.001.jpeg' width='80%' style='vertical-align:middle'></p></h1> <br><b>To setup the service:</b><br><br>1 - First <b>create</b> an account on <a href='https://www.homebridge.ca/'>https://www.homebridge.ca/</a>. <br>2 - Then <b>enter</b> the username and password for your account <b>below</b>. <br>3 - <b>Save</b> the settings and <b>restart</b> homebridge. <br>4 - In the Amazon Alexa Application on your smart phone, <b>search</b> for the Homebridge Skill and enable it. When you enable the skill, it will take you to the <b>https://www.homebridge.ca/</b> website to <b>enable</b> and link the skill to the plugin. <br>5 - You can now ask Alexa to <b>`discover devices`</b> and it should discover your homebridge devices.<br><br>Detailed setup instructions are available <a href='https://github.com/NorthernMan54/homebridge-alexa/blob/master/Installation.md#setup-instructions'>here</a>.<br>",
6
6
  "footerDisplay": "Homebridge Alexa Skill: https://www.amazon.com/Northern-Man-54-Homebridge/dp/B07B9QMTFQ",
7
7
  "schema": {
8
8
  "type": "object",
9
9
  "properties": {
10
10
  "name": {
11
- "title": "Name",
11
+ "title": "<b>Name</b>",
12
12
  "type": "string",
13
13
  "required": true,
14
14
  "default": "Alexa",
15
15
  "description": "Plugin name as displayed in the Homebridge log"
16
16
  },
17
17
  "username": {
18
- "title": "Username",
18
+ "title": "<b>Username</b>",
19
19
  "type": "string",
20
20
  "required": true,
21
21
  "description": "Username for https://www.homebridge.ca/"
22
22
  },
23
23
  "password": {
24
- "title": "Password",
24
+ "title": "<b>Password</b>",
25
25
  "type": "string",
26
26
  "required": true,
27
27
  "description": "Password for https://www.homebridge.ca/"
28
28
  },
29
29
  "pin": {
30
- "title": "Homebridge Pin",
30
+ "title": "<b>Homebridge Pin</b>",
31
31
  "type": "string",
32
32
  "placeholder": "031-45-154",
33
33
  "description": "This needs to match the Homebridge pin set in your config.json file"
34
34
  },
35
35
  "routines": {
36
- "title": " Routines - enables passing of Motion and Contact sensor events to Alexa. For use in the Alexa app to create Routines triggered by these sensors.",
36
+ "title": "<b>Routines</b>",
37
37
  "type": "boolean",
38
- "placeholder": false
38
+ "placeholder": false,
39
+ "description": "Enables passing of Motion and Contact sensor events to Alexa. For use in the Alexa app to create Routines triggered by these sensors."
39
40
  },
40
41
  "blind": {
41
- "title": "Enables natural wording for opening and closing blinds, and window coverings. Not supported in all countries. Defaults to false",
42
+ "title": "<b>Blind</b>",
42
43
  "type": "boolean",
43
- "placeholder": false
44
+ "placeholder": false,
45
+ "description": "Enables natural wording for opening and closing blinds, and window coverings. Not supported in all countries. Defaults to false"
44
46
  },
45
47
  "door": {
46
- "title": "Enables natural wording for opening and closing garage doors. Not supported in all countries. Please note that opening a garage door requires setting a voice pin within the Alexa app. Defaults to false",
48
+ "title": "<b>Door</b>",
47
49
  "type": "boolean",
48
- "placeholder": false
50
+ "placeholder": false,
51
+ "description": "Enables natural wording for opening and closing garage doors. Not supported in all countries. Please note that opening a garage door requires setting a voice pin within the Alexa app. Defaults to false"
49
52
  },
50
53
  "debug": {
51
- "title": "Enable debug level logging to assist in problem investigation",
54
+ "title": "<b>Debug</b>",
52
55
  "type": "boolean",
53
- "placeholder": false
56
+ "placeholder": false,
57
+ "description": "Enable debug level logging to assist in problem investigation."
58
+ },
59
+ "beta": {
60
+ "title": "<b>beta</b>",
61
+ "type": "boolean",
62
+ "placeholder": false,
63
+ "description": "Enable beta test environment. Only available by invitation."
54
64
  },
55
65
  "refresh": {
56
- "title": "Accessory Cache Refresh Interval",
66
+ "title": "<b>Accessory Cache Refresh Interval</b>",
57
67
  "type": "integer",
58
68
  "default": 900,
59
69
  "description": "Frequency of refreshes of the homebridge accessory cache, in seconds. Defaults to 900 Seconds ( 15 minutes ). This is the interval before new devices/homebridge instances are discovered. This should never require changing, unless you are frequently changing your homebridge configuration without restarting the plugin.",
@@ -61,7 +71,7 @@
61
71
  "maximum": 86400
62
72
  },
63
73
  "keepalive": {
64
- "title": "Cloud Server Connection Keepalive",
74
+ "title": "<b>Cloud Server Connection Keepalive</b>",
65
75
  "type": "integer",
66
76
  "default": "5",
67
77
  "description": "Frequency of keepalive messages to cloud server, in minutes. Defaults to 5 minutes. Do not change from default unless requested as part of problem investigation.",
@@ -72,13 +82,38 @@
72
82
  }
73
83
  },
74
84
  "mergeServiceName": {
75
- "title": "Alternate device naming approach",
85
+ "title": "<b>Alternate device naming approach</b>",
76
86
  "type": "boolean",
77
87
  "description": "This is an alternate device naming approach, which combines the internal HomeKit names for a device. It may resolve duplicate device name issues. Do not enable on an existing implementation, as you will lose control of your existing devices.",
78
88
  "placeholder": false
79
89
  },
90
+ "thermostatTurnOn": {
91
+ "title": "<b>Thermostat Turn On Behaviour</b>",
92
+ "description": "Set Thermostat `Turn On` Behaviour to either Heat, Cool or Auto when Alexa is asked to turn on a Thermostat. Defaults to doing nothing and saying `That command does not work on device ...`.",
93
+ "type": "integer",
94
+ "oneOf": [
95
+ {
96
+ "title": "Heat",
97
+ "enum": [
98
+ 1
99
+ ]
100
+ },
101
+ {
102
+ "title": "Cool",
103
+ "enum": [
104
+ 2
105
+ ]
106
+ },
107
+ {
108
+ "title": "Auto",
109
+ "enum": [
110
+ 3
111
+ ]
112
+ }
113
+ ]
114
+ },
80
115
  "CloudTransport": {
81
- "title": "Cloud Server Connection Transport",
116
+ "title": "<b>Cloud Server Connection Transport</b>",
82
117
  "description": "Transport options for cloud server connection. MQTTS - this is the recommended setting. MQTT - this is the original/legacy option. WSS - this is the an alternative transport option.",
83
118
  "type": "string",
84
119
  "default": "mqtts",
@@ -105,15 +140,16 @@
105
140
  ]
106
141
  },
107
142
  "filter": {
108
- "title": "Homebridge Instance Filter",
143
+ "title": "<b>Homebridge Instance Filter</b>",
109
144
  "type": "string",
110
145
  "placeholder": "eg. 192.168.1.122:51826",
111
- "description": "Limits accessories shared with Alexa to a single homebridge instance.",
146
+ "description": "Limits accessories shared with Alexa to a single homebridge instance. Uses ip address and port of homebridge instance.",
112
147
  "pattern": "^[^{}/ :\\\\]+(?::\\d+)?$"
113
148
  },
114
149
  "deviceListHandling": {
115
- "title": "<b>Filtering of devices by name, either allow or ignore.</b>",
150
+ "title": "<b>Device List</b>",
116
151
  "type": "string",
152
+ "description": "Allows filtering of devices by name. You can either allow or ignore a list of device names.",
117
153
  "default": "none",
118
154
  "required": true,
119
155
  "oneOf": [
@@ -144,7 +180,7 @@
144
180
  "type": "string"
145
181
  },
146
182
  "condition": {
147
- "functionBody": "return model.deviceListHandling !== 'null';"
183
+ "functionBody": "if (model.deviceListHandling === 'allow' || model.deviceListHandling === 'deny') { return true } else { return false };"
148
184
  }
149
185
  },
150
186
  "combine": {
@@ -214,6 +250,7 @@
214
250
  "pin",
215
251
  "routines",
216
252
  "debug",
253
+ "thermostatTurnOn",
217
254
  "deviceListHandling",
218
255
  {
219
256
  "key": "deviceList",
@@ -239,7 +276,9 @@
239
276
  "keepalive",
240
277
  "refresh",
241
278
  "filter",
242
- "mergeServiceName"
279
+ "mergeServiceName",
280
+ "blind",
281
+ "door"
243
282
  ]
244
283
  },
245
284
  {
@@ -128,7 +128,7 @@ function alexaDiscovery(message, callback) {
128
128
  // debug('Homebridge Accessory Instance Dump for', mdnsCache[instance].name);
129
129
  output = output + '\ncurl -X PUT ' + mdnsCache[instance].url + '/accessories --header "Content-Type:Application/json" --header "authorization: ' + this.pin + '"\n';
130
130
  }
131
- debug(output);
131
+ // debug(output);
132
132
  this.log("alexaDiscovery - returned %s devices", response.event.payload.endpoints.length);
133
133
  }
134
134
  if (response.event.payload.endpoints.length > 300) {
@@ -137,8 +137,8 @@ function alexaDiscovery(message, callback) {
137
137
  }
138
138
  // debug("Discovery Response", JSON.stringify(response, null, 2));
139
139
  if (this.debug) {
140
- // const fs = require('fs');
141
- // fs.writeFileSync('alexaDiscovery.json', JSON.stringify(response, null, 2));
140
+ const fs = require('fs');
141
+ fs.writeFileSync('alexaDiscovery.json', JSON.stringify(response, null, 2));
142
142
  }
143
143
  callback(null, response);
144
144
  }.bind(this));
@@ -20,10 +20,10 @@ function Characteristic(devices, context) {
20
20
 
21
21
  // Overide Brightness/Rotation Speed with Volume for Fake speakers
22
22
  // debug("Speaker", devices);
23
- if (context.options.speakers && context.options.speakers.some(function(element) {
24
- // debug("SPEAKER", element.manufacturer === context.info.Manufacturer && element.name === context.info.Name, devices.description);
25
- return (element.manufacturer === context.info.Manufacturer && element.name === context.info.Name);
26
- }) && (devices.description === "Brightness" || devices.description === "Rotation Speed")) {
23
+ if (context.options.speakers && context.options.speakers.some(function (element) {
24
+ // debug("SPEAKER", element.manufacturer === context.info.Manufacturer && element.name === context.info.Name, devices.description);
25
+ return (element.manufacturer === context.info.Manufacturer && element.name === context.info.Name);
26
+ }) && (devices.description === "Brightness" || devices.description === "Rotation Speed")) {
27
27
  this.type = "00000119"; // Volume Characteristic
28
28
  this.description = "Volume";
29
29
  } else {
@@ -66,12 +66,12 @@ function _getActions(description, context, devices) {
66
66
  cookie["AdjustPowerLevel"] = messages.cookie(context);
67
67
  cookie["SetPowerLevel"] = messages.cookie(context);
68
68
  break;
69
- /*
70
- case "Configured Name": // Channel Change Hack
71
- cookie["Channel"] = messages.cookie(context);
72
- debug("Channel", context);
73
- break;
74
- */
69
+ /*
70
+ case "Configured Name": // Channel Change Hack
71
+ cookie["Channel"] = messages.cookie(context);
72
+ debug("Channel", context);
73
+ break;
74
+ */
75
75
  case "Active Identifier": // Channel Change Hack
76
76
  cookie["Active Identifier"] = messages.cookie(context);
77
77
  break;
@@ -231,13 +231,13 @@ function _getActions(description, context, devices) {
231
231
  reportState.push(messages.reportState("Alexa.StepSpeaker", context));
232
232
  cookie["AdjustVolume"] = messages.cookie(context);
233
233
  break;
234
- /*
235
- case "Mute": // Speaker volume
236
- // case "91288267": // This is in the homebridge-bose-soundtouch plugin
237
- reportState.push(messages.reportState("Alexa.StepSpeaker", context));
238
- cookie["SetMute"] = messages.cookie(context);
239
- break;
240
- */
234
+ /*
235
+ case "Mute": // Speaker volume
236
+ // case "91288267": // This is in the homebridge-bose-soundtouch plugin
237
+ reportState.push(messages.reportState("Alexa.StepSpeaker", context));
238
+ cookie["SetMute"] = messages.cookie(context);
239
+ break;
240
+ */
241
241
  case "Target Temperature": // Target Temperature
242
242
  reportState.push(messages.reportState("Alexa.ThermostatControllertargetSetpoint", context));
243
243
  // cookie["SetTargetTemperature"] = messages.cookie(context);
@@ -259,9 +259,14 @@ function _getActions(description, context, devices) {
259
259
  // cookie["targetSetpoint"] = messages.cookie(context);
260
260
  // }
261
261
  break;
262
+ case "Target Heating Cooling State":
263
+ // debug('Target Heating Cooling State', context, this);
264
+ if (context.options.thermostatTurnOn) {
265
+ cookie["TurnOn"] = messages.cookieV(context.options.thermostatTurnOn, context); // Defaults to That command does not work
266
+ }
267
+ cookie["TurnOff"] = messages.cookieV(0, context); // OFF
262
268
  case "Target Heater-Cooler State":
263
269
  case "Target Heater Cooler State":
264
- case "Target Heating Cooling State":
265
270
  reportState.push(messages.reportState("Alexa.ThermostatControllerthermostatMode", context));
266
271
  // reportState.push(messages.reportState("Alexa.ThermostatController", context));
267
272
  // Characteristic.TargetHeatingCoolingState.OFF = 0;
@@ -314,7 +319,7 @@ function _getActions(description, context, devices) {
314
319
  cookie["Previous"] = messages.cookieV(6, context);
315
320
  break;
316
321
  default:
317
- // debug("Missing Characteristic '%s' %s - %s", description, context.name, context.function);
322
+ // debug("Missing Characteristic '%s' %s - %s", description, context.name, context.function);
318
323
  }
319
324
  // debug("HP", hapEvents, hapEvents.length);
320
325
  return ({
@@ -21,7 +21,8 @@ function Homebridge(devices, context) {
21
21
  speakers: context.speakers,
22
22
  blind: context.blind,
23
23
  door: context.door,
24
- mergeServiceName: context.mergeServiceName
24
+ mergeServiceName: context.mergeServiceName,
25
+ thermostatTurnOn: context.thermostatTurnOn
25
26
  };
26
27
  this.playback = {};
27
28
  devices.accessories.accessories.forEach(function(element) {
@@ -219,8 +219,9 @@ Service.prototype.toAlexa = function (context) {
219
219
  capabilities = capabilities.concat(messages.lookupCapabilities("ColorController", context.events));
220
220
  }
221
221
  break;
222
- case "Heater Cooler":
223
222
  case "Thermostat":
223
+ capabilities = capabilities.concat(messages.lookupCapabilities("Active", context.events, cookie));
224
+ case "Heater Cooler":
224
225
  /*
225
226
  reportState.push({
226
227
  "interface": "Alexa.ThermostatController",
@@ -227,6 +227,15 @@ function stateToProperties(statusObject, hbResponse) {
227
227
  "timeOfSample": now.toISOString(),
228
228
  "uncertaintyInMilliseconds": 500
229
229
  });
230
+ if (!statusObject.elements.find(x => x.interface.toLowerCase() === "alexa.powercontroller")) {
231
+ properties.push({
232
+ "namespace": "Alexa.PowerController",
233
+ "name": "powerState",
234
+ "value": properties[0].value === "OFF" ? "OFF" : "ON",
235
+ "timeOfSample": now.toISOString(),
236
+ "uncertaintyInMilliseconds": 500
237
+ });
238
+ }
230
239
  break;
231
240
  default:
232
241
  debug("ERROR: statusReport unknown/handled device", element, reportState);
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "homebridge-alexa",
3
- "version": "0.6.9-beta.8",
3
+ "version": "0.6.9",
4
4
  "description": "Control your Homebridge devices with Amazon Alexa.",
5
5
  "main": "plugin.js",
6
6
  "scripts": {
7
7
  "test": "jest --forceExit --detectOpenHandles --verbose=true --silent ",
8
8
  "api": "documentation build plugin.js lib/alexaActions.js lib/alexaLocal.js lib/alexaMessages.js lib/alexaTranslator.js -f md --config docs/documentation.yml > docs/API.md",
9
- "document": "./gh-md-toc --insert README.md;./gh-md-toc --insert Troubleshooting.md;./gh-md-toc --insert Installation.md; rm README.md.orig.* README.md.toc.* Troubleshooting.md.orig.* Troubleshooting.md.toc.* Installation.md.orig.* Installation.md.toc.*",
9
+ "document": "./gh-md-toc --hide-footer README.md ;./gh-md-toc --hide-footer Troubleshooting.md ;./gh-md-toc --hide-footer Installation.md; rm README.md.orig.* README.md.toc.* Troubleshooting.md.orig.* Troubleshooting.md.toc.* Installation.md.orig.* Installation.md.toc.*",
10
10
  "watch": "nodemon"
11
11
  },
12
12
  "nodemonConfig": {
13
13
  "watch": [],
14
- "ext": "js,json",
14
+ "ext": "js",
15
15
  "ignore": [],
16
16
  "exec": "~/npm/bin/homebridge -D -R -P ~/Code",
17
17
  "signal": "SIGTERM",
@@ -23,6 +23,10 @@
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/NorthernMan54/homebridge-alexa.git"
25
25
  },
26
+ "engines": {
27
+ "homebridge": "^1.6.0",
28
+ "node": "^18 || ^20"
29
+ },
26
30
  "keywords": [
27
31
  "alexa",
28
32
  "homebridge-plugin"
@@ -46,9 +50,9 @@
46
50
  "dependencies": {
47
51
  "bottleneck": "2.19.5",
48
52
  "debug": "4.3.4",
49
- "hap-node-client": "0.2.4",
53
+ "hap-node-client": "0.2.7",
50
54
  "is-my-json-valid": "2.20.6",
51
- "mqtt": "5.3.6"
55
+ "mqtt": "5.5.0"
52
56
  },
53
57
  "author": "NorthernMan54",
54
58
  "license": "Apache-2.0",
package/plugin.js CHANGED
@@ -36,6 +36,7 @@ function alexaHome(log, config, api) {
36
36
  this.inputs = config['inputs'] || false; // Array of input devices
37
37
  this.channel = config['channel'] || false; // Array of input devices
38
38
  this.blind = config['blind'] || false; // Use range controller for Blinds
39
+ this.thermostatTurnOn = config['thermostatTurnOn'] || 0; // Default to unsupported
39
40
  this.deviceListHandling = config['deviceListHandling'] || []; // Use ea
40
41
  this.deviceList = config['deviceList'] || []; // Use ea
41
42
  this.door = config['door'] || false; // Use mode controller for Garage Doors
@@ -135,6 +136,7 @@ alexaHome.prototype.didFinishLaunching = function () {
135
136
  Characteristic: Characteristic,
136
137
  inputs: this.inputs,
137
138
  channel: this.channel,
139
+ thermostatTurnOn: this.thermostatTurnOn,
138
140
  blind: this.blind,
139
141
  deviceListHandling: this.deviceListHandling,
140
142
  deviceList: this.deviceList,
@@ -1,93 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- const fs = require("fs");
8
- const semver = require("semver");
9
- const child_process = require("child_process");
10
- const assert = require("assert");
11
-
12
- const BRANCH_VERSION_PATTERN = /^([A-Za-z]*)-(\d+.\d+.\d+)$/
13
-
14
- // Load the contents of the package.json file
15
- const packageJSON = JSON.parse(fs.readFileSync("package.json", "utf8"));
16
-
17
- let refArgument = process.argv[2];
18
- let tagArgument = process.argv[3] || "latest";
19
-
20
- if (refArgument == null) {
21
- console.error("ref argument is missing");
22
- console.error("Usage: npm-version-script.js <ref> [tag]");
23
- process.exit(1);
24
- }
25
-
26
- /**
27
- * Queries the NPM registry for the latest version for the provided tag.
28
- * @param tag The tag to query for.
29
- * @returns {string} Returns the version.
30
- */
31
- function getTagVersionFromNpm(tag) {
32
- try {
33
- return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString("utf8").trim();
34
- } catch (e) {
35
- console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`);
36
- // throw e;
37
- return "0.0.0";
38
- }
39
- }
40
-
41
- function desiredTargetVersion(ref) {
42
- // ref is a GitHub action ref string
43
- if (ref.startsWith("refs/pull/")) {
44
- throw Error("The version script was executed inside a PR!");
45
- }
46
-
47
- assert(ref.startsWith("refs/heads/"))
48
- let branchName = ref.slice("refs/heads/".length);
49
-
50
- let results = branchName.match(BRANCH_VERSION_PATTERN);
51
- if (results != null) {
52
- if (results[1] !== tagArgument) {
53
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`);
54
- }
55
-
56
- return results[2];
57
- }
58
-
59
- // legacy mode were we use the `betaVersion` property in the package.json
60
- if (branchName === "beta" && packageJSON.betaVersion) {
61
- return packageJSON.betaVersion
62
- }
63
-
64
- // legacy mode were we use the `alphaVersion` property in the package.json
65
- if (branchName === "alpha" && packageJSON.alphaVersion) {
66
- return packageJSON.alphaVersion
67
- }
68
-
69
- throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`);
70
- }
71
-
72
- // derive the base version from the branch ref
73
- const baseVersion = desiredTargetVersion(refArgument);
74
-
75
- // query the npm registry for the latest version of the provided tag name
76
- const latestReleasedVersion = getTagVersionFromNpm(tagArgument); // e.g. 0.7.0-beta.12
77
- const latestReleaseBase = semver.inc(latestReleasedVersion, "patch"); // will produce 0.7.0 (removing the preid, needed for the equality check below)
78
-
79
- let publishTag;
80
- if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta or alpha
81
- publishTag = latestReleasedVersion; // set the current latest beta or alpha to be incremented
82
- } else {
83
- publishTag = baseVersion; // start of with a new beta or alpha version
84
- }
85
-
86
- // save the package.json
87
- packageJSON.version = publishTag;
88
- fs.writeFileSync("package.json", JSON.stringify(packageJSON, null, 2));
89
-
90
- // perform the same change to the package-lock.json
91
- const packageLockJSON = JSON.parse(fs.readFileSync("package-lock.json", "utf8"));
92
- packageLockJSON.version = publishTag;
93
- fs.writeFileSync("package-lock.json", JSON.stringify(packageLockJSON, null, 2));
package/gh-md-toc.1 DELETED
@@ -1,421 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- #
4
- # Steps:
5
- #
6
- # 1. Download corresponding html file for some README.md:
7
- # curl -s $1
8
- #
9
- # 2. Discard rows where no substring 'user-content-' (github's markup):
10
- # awk '/user-content-/ { ...
11
- #
12
- # 3.1 Get last number in each row like ' ... </span></a>sitemap.js</h1'.
13
- # It's a level of the current header:
14
- # substr($0, length($0), 1)
15
- #
16
- # 3.2 Get level from 3.1 and insert corresponding number of spaces before '*':
17
- # sprintf("%*s", (level-1)*'"$nb_spaces"', "")
18
- #
19
- # 4. Find head's text and insert it inside "* [ ... ]":
20
- # substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
21
- #
22
- # 5. Find anchor and insert it inside "(...)":
23
- # substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
24
- #
25
-
26
- gh_toc_version="0.10.0"
27
-
28
- gh_user_agent="gh-md-toc v$gh_toc_version"
29
-
30
- #
31
- # Download rendered into html README.md by its url.
32
- #
33
- #
34
- gh_toc_load() {
35
- local gh_url=$1
36
-
37
- if type curl &>/dev/null; then
38
- curl --user-agent "$gh_user_agent" -s "$gh_url"
39
- elif type wget &>/dev/null; then
40
- wget --user-agent="$gh_user_agent" -qO- "$gh_url"
41
- else
42
- echo "Please, install 'curl' or 'wget' and try again."
43
- exit 1
44
- fi
45
- }
46
-
47
- #
48
- # Converts local md file into html by GitHub
49
- #
50
- # -> curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown
51
- # <p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>'"
52
- gh_toc_md2html() {
53
- local gh_file_md=$1
54
- local skip_header=$2
55
-
56
- URL=https://api.github.com/markdown/raw
57
-
58
- if [ -n "$GH_TOC_TOKEN" ]; then
59
- TOKEN=$GH_TOC_TOKEN
60
- else
61
- TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
62
- if [ -f "$TOKEN_FILE" ]; then
63
- TOKEN="$(cat "$TOKEN_FILE")"
64
- fi
65
- fi
66
- if [ -n "${TOKEN}" ]; then
67
- AUTHORIZATION="Authorization: token ${TOKEN}"
68
- fi
69
-
70
- local gh_tmp_file_md=$gh_file_md
71
- if [ "$skip_header" = "yes" ]; then
72
- if grep -Fxq "<!--te-->" "$gh_src"; then
73
- # cut everything before the toc
74
- gh_tmp_file_md=$gh_file_md~~
75
- sed '1,/<!--te-->/d' "$gh_file_md" > "$gh_tmp_file_md"
76
- fi
77
- fi
78
-
79
- # echo $URL 1>&2
80
- OUTPUT=$(curl -s \
81
- --user-agent "$gh_user_agent" \
82
- --data-binary @"$gh_tmp_file_md" \
83
- -H "Content-Type:text/plain" \
84
- -H "$AUTHORIZATION" \
85
- "$URL")
86
-
87
- rm -f "${gh_file_md}~~"
88
-
89
- if [ "$?" != "0" ]; then
90
- echo "XXNetworkErrorXX"
91
- fi
92
- if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then
93
- echo "XXRateLimitXX"
94
- else
95
- echo "${OUTPUT}"
96
- fi
97
- }
98
-
99
-
100
- #
101
- # Is passed string url
102
- #
103
- gh_is_url() {
104
- case $1 in
105
- https* | http*)
106
- echo "yes";;
107
- *)
108
- echo "no";;
109
- esac
110
- }
111
-
112
- #
113
- # TOC generator
114
- #
115
- gh_toc(){
116
- local gh_src=$1
117
- local gh_src_copy=$1
118
- local gh_ttl_docs=$2
119
- local need_replace=$3
120
- local no_backup=$4
121
- local no_footer=$5
122
- local indent=$6
123
- local skip_header=$7
124
-
125
- if [ "$gh_src" = "" ]; then
126
- echo "Please, enter URL or local path for a README.md"
127
- exit 1
128
- fi
129
-
130
-
131
- # Show "TOC" string only if working with one document
132
- if [ "$gh_ttl_docs" = "1" ]; then
133
-
134
- echo "Table of Contents"
135
- echo "================="
136
- echo ""
137
- gh_src_copy=""
138
-
139
- fi
140
-
141
- if [ "$(gh_is_url "$gh_src")" == "yes" ]; then
142
- gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy" "$indent"
143
- if [ "${PIPESTATUS[0]}" != "0" ]; then
144
- echo "Could not load remote document."
145
- echo "Please check your url or network connectivity"
146
- exit 1
147
- fi
148
- if [ "$need_replace" = "yes" ]; then
149
- echo
150
- echo "!! '$gh_src' is not a local file"
151
- echo "!! Can't insert the TOC into it."
152
- echo
153
- fi
154
- else
155
- local rawhtml
156
- rawhtml=$(gh_toc_md2html "$gh_src" "$skip_header")
157
- if [ "$rawhtml" == "XXNetworkErrorXX" ]; then
158
- echo "Parsing local markdown file requires access to github API"
159
- echo "Please make sure curl is installed and check your network connectivity"
160
- exit 1
161
- fi
162
- if [ "$rawhtml" == "XXRateLimitXX" ]; then
163
- echo "Parsing local markdown file requires access to github API"
164
- echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting"
165
- TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
166
- echo "or place GitHub auth token here: ${TOKEN_FILE}"
167
- exit 1
168
- fi
169
- local toc
170
- toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy" "$indent"`
171
- echo "$toc"
172
- if [ "$need_replace" = "yes" ]; then
173
- if grep -Fxq "<!--ts-->" "$gh_src" && grep -Fxq "<!--te-->" "$gh_src"; then
174
- echo "Found markers"
175
- else
176
- echo "You don't have <!--ts--> or <!--te--> in your file...exiting"
177
- exit 1
178
- fi
179
- local ts="<\!--ts-->"
180
- local te="<\!--te-->"
181
- local dt
182
- dt=$(date +'%F_%H%M%S')
183
- local ext=".orig.${dt}"
184
- local toc_path="${gh_src}.toc.${dt}"
185
- local toc_createdby="<!-- Created by https://github.com/ekalinin/github-markdown-toc -->"
186
- local toc_footer
187
- toc_footer="<!-- Added by: `whoami`, at: `date` -->"
188
- # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
189
- # clear old TOC
190
- sed -i"${ext}" "/${ts}/,/${te}/{//!d;}" "$gh_src"
191
- # create toc file
192
- echo "${toc}" > "${toc_path}"
193
- if [ "${no_footer}" != "yes" ]; then
194
- echo -e "\n${toc_createdby}\n${toc_footer}\n" >> "$toc_path"
195
- fi
196
-
197
- # insert toc file
198
- if ! sed --version > /dev/null 2>&1; then
199
- sed -i "" "/${ts}/r ${toc_path}" "$gh_src"
200
- else
201
- sed -i "/${ts}/r ${toc_path}" "$gh_src"
202
- fi
203
- echo
204
- if [ "${no_backup}" = "yes" ]; then
205
- rm "$toc_path" "$gh_src$ext"
206
- fi
207
- echo "!! TOC was added into: '$gh_src'"
208
- if [ -z "${no_backup}" ]; then
209
- echo "!! Origin version of the file: '${gh_src}${ext}'"
210
- echo "!! TOC added into a separate file: '${toc_path}'"
211
- fi
212
- echo
213
- fi
214
- fi
215
- }
216
-
217
- #
218
- # Grabber of the TOC from rendered html
219
- #
220
- # $1 - a source url of document.
221
- # It's need if TOC is generated for multiple documents.
222
- # $2 - number of spaces used to indent.
223
- #
224
- gh_toc_grab() {
225
-
226
- href_regex="/href=\"[^\"]+?\"/"
227
- common_awk_script='
228
- modified_href = ""
229
- split(href, chars, "")
230
- for (i=1;i <= length(href); i++) {
231
- c = chars[i]
232
- res = ""
233
- if (c == "+") {
234
- res = " "
235
- } else {
236
- if (c == "%") {
237
- res = "\\x"
238
- } else {
239
- res = c ""
240
- }
241
- }
242
- modified_href = modified_href res
243
- }
244
- print sprintf("%*s", (level-1)*'"$2"', "") "* [" text "](" gh_url modified_href ")"
245
- '
246
- if [ "`uname -s`" == "OS/390" ]; then
247
- grepcmd="pcregrep -o"
248
- echoargs=""
249
- awkscript='{
250
- level = substr($0, 3, 1)
251
- text = substr($0, match($0, /<\/span><\/a>[^<]*<\/h/)+11, RLENGTH-14)
252
- href = substr($0, match($0, '$href_regex')+6, RLENGTH-7)
253
- '"$common_awk_script"'
254
- }'
255
- else
256
- grepcmd="grep -Eo"
257
- echoargs="-e"
258
- awkscript='{
259
- level = substr($0, 3, 1)
260
- text = substr($0, match($0, /">.*<\/h/)+2, RLENGTH-5)
261
- href = substr($0, match($0, '$href_regex')+6, RLENGTH-7)
262
- '"$common_awk_script"'
263
- }'
264
- fi
265
-
266
- # if closed <h[1-6]> is on the new line, then move it on the prev line
267
- # for example:
268
- # was: The command <code>foo1</code>
269
- # </h1>
270
- # became: The command <code>foo1</code></h1>
271
- sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
272
-
273
- # Sometimes a line can start with <span>. Fix that.
274
- sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<span/<span/g' |
275
-
276
- # find strings that corresponds to template
277
- $grepcmd '<h.*class="heading-element".*</a' |
278
-
279
- # remove code tags
280
- sed 's/<code>//g' | sed 's/<\/code>//g' |
281
-
282
- # remove g-emoji
283
- sed 's/<g-emoji[^>]*[^<]*<\/g-emoji> //g' |
284
-
285
- # now all rows are like:
286
- # <h1 class="heading-element">title</h1><a href="..."><span>..</span></a>
287
- # format result line
288
- # * $0 - whole string
289
- # * last element of each row: "</hN" where N in (1,2,3,...)
290
- echo $echoargs "$(awk -v "gh_url=$1" "$awkscript")"
291
- }
292
-
293
- # perl -lpE 's/(\[[^\]]*\]\()(.*?)(\))/my ($pre, $in, $post)=($1, $2, $3) ; $in =~ s{\+}{ }g; $in =~ s{%}{\\x}g; $pre.$in.$post/ems')"
294
-
295
- #
296
- # Returns filename only from full path or url
297
- #
298
- gh_toc_get_filename() {
299
- echo "${1##*/}"
300
- }
301
-
302
- show_version() {
303
- echo "$gh_toc_version"
304
- echo
305
- echo "os: `uname -s`"
306
- echo "arch: `uname -m`"
307
- echo "kernel: `uname -r`"
308
- echo "shell: `$SHELL --version`"
309
- echo
310
- for tool in curl wget grep awk sed; do
311
- printf "%-5s: " $tool
312
- if type $tool &>/dev/null; then
313
- $tool --version | head -n 1
314
- else
315
- echo "not installed"
316
- fi
317
- done
318
- }
319
-
320
- show_help() {
321
- local app_name
322
- app_name=$(basename "$0")
323
- echo "GitHub TOC generator ($app_name): $gh_toc_version"
324
- echo ""
325
- echo "Usage:"
326
- echo " $app_name [options] src [src] Create TOC for a README file (url or local path)"
327
- echo " $app_name - Create TOC for markdown from STDIN"
328
- echo " $app_name --help Show help"
329
- echo " $app_name --version Show version"
330
- echo ""
331
- echo "Options:"
332
- echo " --indent <NUM> Set indent size. Default: 3."
333
- echo " --insert Insert new TOC into original file. For local files only. Default: false."
334
- echo " See https://github.com/ekalinin/github-markdown-toc/issues/41 for details."
335
- echo " --no-backup Remove backup file. Set --insert as well. Default: false."
336
- echo " --hide-footer Do not write date & author of the last TOC update. Set --insert as well. Default: false."
337
- echo " --skip-header Hide entry of the topmost headlines. Default: false."
338
- echo " See https://github.com/ekalinin/github-markdown-toc/issues/125 for details."
339
- echo ""
340
- }
341
-
342
- #
343
- # Options handlers
344
- #
345
- gh_toc_app() {
346
- local need_replace="no"
347
- local indent=3
348
-
349
- if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
350
- show_help
351
- return
352
- fi
353
-
354
- if [ "$1" = '--version' ]; then
355
- show_version
356
- return
357
- fi
358
-
359
- if [ "$1" = '--indent' ]; then
360
- indent="$2"
361
- shift 2
362
- fi
363
-
364
- if [ "$1" = "-" ]; then
365
- if [ -z "$TMPDIR" ]; then
366
- TMPDIR="/tmp"
367
- elif [ -n "$TMPDIR" ] && [ ! -d "$TMPDIR" ]; then
368
- mkdir -p "$TMPDIR"
369
- fi
370
- local gh_tmp_md
371
- if [ "`uname -s`" == "OS/390" ]; then
372
- local timestamp
373
- timestamp=$(date +%m%d%Y%H%M%S)
374
- gh_tmp_md="$TMPDIR/tmp.$timestamp"
375
- else
376
- gh_tmp_md=$(mktemp "$TMPDIR/tmp.XXXXXX")
377
- fi
378
- while read -r input; do
379
- echo "$input" >> "$gh_tmp_md"
380
- done
381
- gh_toc_md2html "$gh_tmp_md" | gh_toc_grab "" "$indent"
382
- return
383
- fi
384
-
385
- if [ "$1" = '--insert' ]; then
386
- need_replace="yes"
387
- shift
388
- fi
389
-
390
- if [ "$1" = '--no-backup' ]; then
391
- need_replace="yes"
392
- no_backup="yes"
393
- shift
394
- fi
395
-
396
- if [ "$1" = '--hide-footer' ]; then
397
- need_replace="yes"
398
- no_footer="yes"
399
- shift
400
- fi
401
-
402
- if [ "$1" = '--skip-header' ]; then
403
- skip_header="yes"
404
- shift
405
- fi
406
-
407
-
408
- for md in "$@"
409
- do
410
- echo ""
411
- gh_toc "$md" "$#" "$need_replace" "$no_backup" "$no_footer" "$indent" "$skip_header"
412
- done
413
-
414
- echo ""
415
- echo "<!-- Created by https://github.com/ekalinin/github-markdown-toc -->"
416
- }
417
-
418
- #
419
- # Entry point
420
- #
421
- gh_toc_app "$@"