├── CHANGELOG.md ├── LICENSE ├── README.md └── irdb2broadlinkha.bash /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | #### 06/01/2018 3 | check for missing pronto codes on irdb 4 | process all files in a directory 5 | add a match pattern for function name 6 | download required tools and store in work dir 7 | sanitize more characters disallowed in keys 8 | 9 | #### 29/12/2017 10 | Initial release 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | Creates HomeAssistant's .yaml containing Broadlink IR codes for entire remotes found in the irdb (`https://github.com/probonopd/irdb/tree/master/codes`) or lirc (`https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/`) databases. 4 | 5 | **It is currently suggested to try irdb first as converting lirc devices is much slower right now** 6 | 7 | 8 | # Download 9 | Clone this git repo or download the script using curl: 10 | 11 | curl https://raw.githubusercontent.com/molexx/irdb2broadlinkha/master/irdb2broadlinkha.bash -o irdb2broadlinkha.bash 12 | 13 | # Dependencies 14 | 15 | Will be automatically downloaded and stored in the work dir 'irdb2broadlinkha-work'. 16 | 17 | 18 | `pronto2broadlink.py` from: 19 | 20 | https://gist.githubusercontent.com/appden/42d5272bf128125b019c45bc2ed3311f/raw/bdede927b231933df0c1d6d47dcd140d466d9484/pronto2broadlink.py 21 | 22 | 23 | `IrpTransmogrifier` from: 24 | 25 | https://github.com/bengtmartensson/IrpTransmogrifier 26 | 27 | 28 | 29 | # Usage 30 | 31 | Find your remote in irdb under: 32 | 33 | > https://github.com/probonopd/irdb/tree/master/codes 34 | 35 | note the path of the .csv file under the codes/ directory, e.g. `Sky/Unknown_DVB-S/0,12.csv` 36 | 37 | or the lirc config under: 38 | 39 | > https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/ 40 | 41 | note the path of the .lircd.conf file under the remotes/ directory, e.g. `apple/A1294.lircd.conf` 42 | 43 | 44 | Then run this script with parameters: 45 | - The path to the .csv/.conf as determined above, or an irdb directory path to process all the remotes in that directory 46 | - Prefix to use for the switch id and friendly name in the HA config 47 | - (optional) search pattern to match the function name against - e.g. POWER. Useful for very large remotes or when pulling a directory full of remotes. 48 | 49 | 50 | e.g.: 51 | 52 | ./irdb2broadlinkha.bash 'Sky/Unknown_DVB-S/0,12.csv' Sky_ 53 | 54 | 55 | This will output the YAML ready to be pasted into your HomeAssistant config. 56 | 57 | To save it to a file use unix redirection `>`: 58 | 59 | ./irdb2broadlinkha.bash 'Sky/Unknown_DVB-S/0,12.csv' Sky_ >sky.yaml 60 | 61 | 62 | As this can generate many lines it clutters up `configuration.yaml` so it is neater to have each IR device in its own file and include it from `configuration.yaml`. 63 | One way to do that is make a directory for the remotes - e.g. `broadlink` - then use HA's `!include_dir_merge_named` to merge all files contained in that directory into 64 | the broadlink switches configuration. 65 | 66 | 67 | e.g., `configuration.yaml`: 68 | 69 | - platform: broadlink 70 | mac: 'xx:xx:xx:xx:xx:xx' 71 | host: 192.168.1.xx 72 | timeout: 15 73 | friendly_name: "Broadlink" 74 | switches: 75 | !include_dir_merge_named broadlink 76 | 77 | 78 | then run `irdb2broadlinkha.bash` for each remote: 79 | 80 | ./irdb2broadlinkha.bash 'Sky/Unknown_DVB-S/0,12.csv' Sky_ >~/.homeassistant/broadlink/sky.yaml 81 | 82 |    `./irdb2broadlinkha.bash 'Yamaha/Receiver/120%2C-1.csv' amp_ >~/.homeassistant/broadlink/yamaha_receiver.yaml` 83 | 84 | 85 | 86 | # Discovery assistance mode 87 | 88 | When you don't know which remote you need from irdb this tool can download all the remotes in a directory and process them all. 89 | Pass a search pattern (third parameter) of "POWER" to just get the power buttons, then go through them manually until you find the ones that work for your device. 90 | e.g.: 91 | 92 |    `./irdb2broadlinkha.bash 'Yamaha/Receiver' amptest_ POWER >~/.homeassistant/broadlink/yamaha_all_test.yaml` 93 | -------------------------------------------------------------------------------- /irdb2broadlinkha.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Requires pronto2broadlink.py from: https://gist.githubusercontent.com/appden/42d5272bf128125b019c45bc2ed3311f/raw/bdede927b231933df0c1d6d47dcd140d466d9484/pronto2broadlink.py 5 | # 6 | # 7 | # 8 | 9 | 10 | WORKDIR="irdb2broadlinkha-work" 11 | TEMP_CSV_FILENAME="current.csv" 12 | 13 | PRONTO2BROADLINK_DOWNLOAD="https://gist.githubusercontent.com/appden/42d5272bf128125b019c45bc2ed3311f/raw/bdede927b231933df0c1d6d47dcd140d466d9484/pronto2broadlink.py" 14 | IRPTRANSMORGRIFIER_DOWNLOAD="https://github.com/bengtmartensson/IrpTransmogrifier/releases/download/Version-0.2.0/IrpTransmogrifier-0.2.0-bin.zip" 15 | 16 | 17 | mkdir -p "${WORKDIR}" 18 | rm -f "${WORKDIR}/${TEMP_CSV_FILENAME}" 19 | 20 | 21 | function debug() { 22 | echo "${1}" >&2 23 | : 24 | } 25 | 26 | function error() { 27 | echo "ERROR: ${1}" >&2 28 | } 29 | 30 | 31 | # PROTOCOL, DEVICE, SUBDEVICE, FUNCTION 32 | function signalToPronto() { 33 | local PROTOCOL="$1" 34 | local DEVICE="$2" 35 | local SUBDEVICE="$3" 36 | local FUNCTION="$4" 37 | 38 | local SIGNAL="${PROTOCOL}+${DEVICE}+${SUBDEVICE}+${FUNCTION}" 39 | 40 | PRONTO="" 41 | debug "signalToPronto: ${SIGNAL}..." 42 | PRONTO=$(curl --data "signal=${SIGNAL}" "http://irdb.tk/encode/" -s -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Content-Type: application/x-www-form-urlencoded" | grep "=\"sendPronto" | sed -r -e "s/.*sendPronto\(([^\)]*).*/\1/g" | tr -d "'") 43 | debug "signalToPronto: ${SIGNAL}, pronto hex: ${PRONTO}" 44 | } 45 | 46 | # PRONTO 47 | function prontoToBroadlinkHex() { 48 | local PRONTO="${1}" 49 | BROADLINKHEX=$(python2 "${P2BL}" "${PRONTO}") 50 | } 51 | 52 | 53 | 54 | function prontoToYaml() { 55 | local INDENT="${1}" 56 | local NAME="${2}" 57 | local PRONTO="${3}" 58 | 59 | prontoToBroadlinkHex "${PRONTO}" 60 | debug "BroadlinkHex: ${BROADLINKHEX}" 61 | local BROADLINKB64=$(echo -e "${BROADLINKHEX}" | xxd -r -p | base64 --wrap=0) 62 | broadlinkB64ToYaml "${INDENT}" "${NAME_PREFIX}${fnname}" "${BROADLINKB64}" 63 | } 64 | 65 | 66 | #IRDB_CSV_PATH 67 | function downloadIrdbCsv() { 68 | local URL="https://cdn.rawgit.com/probonopd/irdb/master/codes/${1}" 69 | local TARGET="${WORKDIR}/${TEMP_CSV_FILENAME}" 70 | 71 | debug "downloading '${URL}' to '${TARGET}'..." 72 | curl -s "${URL}" -o "${TARGET}" 73 | } 74 | 75 | 76 | #CSVPATH, NAME_PREFIX, INDENT 77 | function loopAroundCsv() { 78 | local LOCAL_CSV_PATH="${1}" 79 | local REMOTE_CSV_PATH="${2}" 80 | local NAME_PREFIX="${3}" 81 | local INDENT="${4}" 82 | local FUNCTION_PATTERN="${5}" 83 | 84 | [ ! -f "${LOCAL_CSV_PATH}" ] && { echo "${LOCAL_CSV_PATH} file not found"; exit 99; } 85 | 86 | local NUM_LINES=$(wc -l <"${LOCAL_CSV_PATH}") 87 | #debug "file '${LOCAL_CSV_PATH}' has `wc -l ${LOCAL_CSV_PATH}` lines..." 88 | debug "file '${REMOTE_CSV_PATH}' has ${NUM_LINES} lines, looking for functions matching '${FUNCTION_PATTERN}'..." 89 | 90 | #skip header line 91 | sed 1d "${LOCAL_CSV_PATH}" | 92 | while IFS=, read fnname protocol device subdevice fn 93 | do 94 | if [[ "${fnname}" != "" ]] ; then 95 | #debug "fnname $fnname, protocol: $protocol, device: $device, subdevice: $subdevice, fn: $fn" 96 | shopt -s nocasematch 97 | if [[ "${FUNCTION_PATTERN}" == "" ]] || [[ "${fnname}" =~ "${FUNCTION_PATTERN}" ]] ; then 98 | if [[ "${FUNCTION_PATTERN}" != "" ]] ; then 99 | debug "fnname '${fnname}' matches pattern '${FUNCTION_PATTERN}'..." 100 | fi 101 | 102 | # signalToBroadlinkB64 "$protocol" "$device" "$subdevice" "$fn" 103 | # #debug "${fnname}: ${BROADLINKB64}" 104 | # if [[ "${BROADLINKB64}" != "" ]] ; then 105 | # broadlinkB64ToYaml "${INDENT}" "${NAME_PREFIX}${fnname}" "${BROADLINKB64}" 106 | # else 107 | # error "signalToBroadlinkB64 returned empty for '$fnname': '$protocol' '$device' '$subdevice' '$fn'" 108 | # fi 109 | signalToPronto "$protocol" "$device" "$subdevice" "$fn" 110 | if [[ "${PRONTO}" != "" ]] && [[ "${PRONTO}" != "None" ]] ; then 111 | prontoToYaml "${INDENT}" "${NAME_PREFIX}${fnname}" "${PRONTO}" 112 | else 113 | error "signalToPronto '${protocol}' '${device}' '${subdevice}' '${fn}' returned no pronto code. Check that the pronto code is available on http://irdb.tk." 114 | fi 115 | debug "" 116 | else 117 | #debug "fnname '${fnname}' does not match pattern '${FUNCTION_PATTERN}', skipping" 118 | : 119 | fi 120 | shopt -u nocasematch 121 | else 122 | error "${NAME_PREFIX}: first column empty, ignoring line." 123 | fi 124 | done 125 | } 126 | 127 | 128 | arr=() 129 | 130 | function broadlinkB64ToYaml() { 131 | local INDENT="${1}" 132 | #local NAME_PREFIX="${2}" 133 | local NAME="${2}" 134 | local CODEB64="${3}" 135 | 136 | #sky_0: 137 | # friendly_name: "Sky 0" 138 | # command_on: 'JgA0AFcdDg4ODg4dDh0dDg4ODg4ODg4ODg4ODg4OHQ4OHQ4ODg4ODg4ODg4ODg4ODg4ODg4ADM8NBQAA' 139 | # command_off: 'JgA0AFcdDg4ODg4dDh0dDg4ODg4ODg4ODg4ODg4OHQ4OHQ4ODg4ODg4ODg4ODg4ODg4ODg4ADM8NBQAA' 140 | 141 | 142 | #sanitize NAME for use as a key 143 | local sname="${NAME,,}" #lowercase 144 | sname="${sname// /_}" #remove spaces 145 | sname="${sname////_}" #remove forward slashes 146 | sname="${sname//+/_plus}" #remove plus 147 | sname="${sname//-/_}" #remove hyphen/minus 148 | sname="${sname//./_}" #remove periods 149 | sname="${sname//,/_}" #remove commas 150 | sname="${sname//:/_}" #remove colons 151 | sname="${sname//(/_}" #remove open bracket 152 | sname="${sname//)/_}" #remove close bracket 153 | sname="${sname//^/_up}" #remove hat 154 | 155 | local suffix="" 156 | 157 | count=1 158 | while [[ " ${arr[*]} " == *" $sname$suffix "* ]]; do 159 | debug "key '$sname$suffix' already used..." 160 | ((count++)) 161 | suffix="_${count}" 162 | done 163 | 164 | sname="${sname}${suffix}" 165 | arr+=("${sname}") 166 | 167 | debug "writing yaml entry for '${NAME}' (sanitized: '${sname}')..." 168 | 169 | echo "${INDENT}'${sname}':" 170 | echo "${INDENT} friendly_name: \"${NAME}${suffix}\"" 171 | echo "${INDENT} command_on: '${CODEB64}'" 172 | echo "${INDENT} " 173 | } 174 | 175 | 176 | 177 | 178 | 179 | function lircFileToYaml() { 180 | local CONF_PATH="${1}" 181 | local NAME_PREFIX="${2}" 182 | local MATCH_PATTERN="${3}" 183 | 184 | #downloadIrdbCsv "${IRDB_CSV_PATH}" 185 | local URL="https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/${CONF_PATH}?format=raw" 186 | local LIRC_CONF="${WORKDIR}/lircd.conf" 187 | debug "downloading lirc config from '${URL}' to '${LIRC_CONF}'..." 188 | curl --fail -s "${URL}" -o "${LIRC_CONF}" 189 | if [[ $? != 0 ]] ; then 190 | error "failed to download lirc config '${URL}'" 191 | exit 5 192 | fi 193 | 194 | debug "downloaded lirc config to '${LIRC_CONF}'." 195 | 196 | local IRP="${WORKDIR}/irp" 197 | local IRP_SED="${WORKDIR}/irp.sed" 198 | #"${WORKDIR}/iptransmorgifier/irptransmogrifier.sh" 199 | debug "converting lirc config to irp using irptransmogrifier..." 200 | "${IRPTM}" lirc "${LIRC_CONF}" >"${IRP}" 201 | cat "${IRP}" | sed -e s/^[^:]\*:// >"${IRP_SED}" 202 | debug "irp created." 203 | 204 | local BUTTON_CODES="${WORKDIR}/buttons" 205 | awk '/begin codes/{flag=1;next}/end codes/{flag=0}flag' "${LIRC_CONF}" >"${BUTTON_CODES}" 206 | 207 | cat "${BUTTON_CODES}" | while read fnname code comment 208 | do 209 | debug "function: '$fnname', code: '$code', comment: '${comment}'." 210 | #"${IRPTM}" render -p -i `cat "${IRP_SED}"` -n F=0xc738 211 | debug "running irptransmogrifier for '$fnname', code: '$code'..." 212 | local PRONTO="$("${IRPTM}" render -p -i `cat "${IRP_SED}"` -n F=${code})" 213 | debug "pronto: $PRONTO" 214 | prontoToYaml "" "${NAME_PREFIX}${fnname}" "${PRONTO}" 215 | done 216 | 217 | debug "done looping around buttons." 218 | 219 | #"${WORKDIR/iptransmorgifier/irptransmogrifier.sh" 220 | 221 | #loopAroundCsv "${WORKDIR}/${TEMP_CSV_FILENAME}" "${IRDB_CSV_PATH}" "${NAME_PREFIX}" "" "${MATCH_PATTERN}" 222 | } 223 | 224 | 225 | 226 | function irdbFileToYaml() { 227 | local IRDB_CSV_PATH="${1}" 228 | local NAME_PREFIX="${2}" 229 | local MATCH_PATTERN="${3}" 230 | 231 | downloadIrdbCsv "${IRDB_CSV_PATH}" 232 | 233 | loopAroundCsv "${WORKDIR}/${TEMP_CSV_FILENAME}" "${IRDB_CSV_PATH}" "${NAME_PREFIX}" "" "${MATCH_PATTERN}" 234 | } 235 | 236 | 237 | 238 | function irdbDirToYaml() { 239 | local IRDB_PATH="${1}" 240 | local NAME_PREFIX="${2}" 241 | local MATCH_PATTERN="${3}" 242 | 243 | curl -s "https://api.github.com/repos/probonopd/irdb/contents/codes/${IRDB_PATH}" | jq -r ".[] | .name" | while read f 244 | do 245 | downloadIrdbCsv "${IRDB_PATH}/${f}" 246 | loopAroundCsv "${WORKDIR}/${TEMP_CSV_FILENAME}" "${IRDB_PATH}/${f}" "${NAME_PREFIX}_${f}_" "" "${MATCH_PATTERN}" 247 | done 248 | } 249 | 250 | function downloadIrpTransmogrifier() { 251 | #local URL="https://github.com/bengtmartensson/IrpTransmogrifier/releases/download/Version-0.2.0/IrpTransmogrifier-0.2.0-bin.zip" 252 | local URL="${IRPTRANSMORGRIFIER_DOWNLOAD}" 253 | local TARGET="${WORKDIR}/IrpTransmogrifier-bin.zip" 254 | debug "downloading IrpTransmogrifier from '${URL}' to '${TARGET}'..." 255 | curl --fail -L "${URL}" -o "${TARGET}" 256 | local CURL_RC=$? 257 | debug "download of IrpTransmogrifier returned: $CURL_RC" 258 | if [[ $CURL_RC != 0 ]] ; then 259 | error "failed to download IrpTransmogrifier from '${URL}'" 260 | exit 5 261 | fi 262 | 263 | cd "${WORKDIR}" 264 | mkdir irptransmogrifier 265 | cd irptransmogrifier 266 | unzip ../IrpTransmogrifier-bin.zip >/dev/null 267 | local UNZIP_RC=$? 268 | debug "unzip of IrpTransmogrifier returned: $UNZIP_RC" 269 | cd .. 270 | if [[ ${UNZIP_RC} == 0 ]] ; then 271 | rm IrpTransmogrifier-bin.zip 272 | else 273 | rmdir irptransmogrifier 274 | cd .. 275 | error "failed to unzip '${WORKDIR}/IrpTransmogrifier-bin.zip', IrpTransmogrifier not installed." 276 | exit 5 277 | fi 278 | cd .. 279 | } 280 | 281 | function ensureIrpTransmogrifier() { 282 | which java >/dev/null 283 | if [[ $? != 0 ]] ; then 284 | error "java command not available, a JRE is needed by IrpTransmogrifier which is needed to convert lirc config files" 285 | exit 5 286 | fi 287 | 288 | if [[ -e "${WORKDIR}/irptransmogrifier" ]] ; then 289 | debug "irptransmogrifier found at '${WORKDIR}/irptransmogrifier'." 290 | else 291 | debug "irptransmogrifier not found at '${WORKDIR}/irptransmogrifier', downloading it..." 292 | downloadIrpTransmogrifier 293 | fi 294 | IRPTM="${WORKDIR}/irptransmogrifier/irptransmogrifier.sh" 295 | } 296 | 297 | 298 | function downloadPronto2Broadlink() { 299 | local URL="${PRONTO2BROADLINK_DOWNLOAD}" 300 | local TARGET="${WORKDIR}/pronto2broadlink.py" 301 | debug "downloading pronto2broadlink.py from '${URL}' to '${TARGET}'..." 302 | curl --fail -L "${URL}" -o "${TARGET}" 303 | local CURL_RC=$? 304 | debug "download of pronto2broadlink.py returned: $CURL_RC" 305 | if [[ $CURL_RC != 0 ]] ; then 306 | error "failed to download pronto2broadlink.py from '${URL}'" 307 | exit 5 308 | fi 309 | } 310 | 311 | function ensurePronto2Broadlink() { 312 | which python2 >/dev/null 313 | if [[ $? != 0 ]] ; then 314 | error "python2 command not available, it is needed by pronto2broadlink.py which is needed to convert pronto codes to broadlink codes" 315 | exit 5 316 | fi 317 | 318 | if [[ -e "${WORKDIR}/pronto2broadlink.py" ]] ; then 319 | debug "pronto2broadlink.py found at '${WORKDIR}/pronto2broadlink.py'." 320 | else 321 | debug "pronto2broadlink.py not found at '${WORKDIR}/pronto2broadlink.py', downloading it..." 322 | downloadPronto2Broadlink 323 | fi 324 | P2BL="${WORKDIR}/pronto2broadlink.py" 325 | } 326 | 327 | 328 | function usage() { 329 | error "Usage:" 330 | error " $0 \"path to irdb .csv file or directory; or path to lircd.conf file\" \"configured name prefix\" [\"functions matching pattern\"]" 331 | error " e.g.: $0 \"Yamaha/Receiver/120,-1.csv\" \"Amp \" (irdb)" 332 | error " $0 \"Yamaha/Receiver\" \"Amp \" \"POWER\" (parse all remotes in the irdb directory, only add POWER commands)" 333 | error " $0 \"apple/A1294.lircd.conf\" appletv_ >appletv.yaml (lirc)" 334 | } 335 | 336 | 337 | 338 | IRDB_PATH="${1}" 339 | NAME_PREFIX="${2}" 340 | MATCH_PATTERN="${3}" 341 | 342 | if [[ "${IRDB_PATH}" == "" ]] || [[ "${NAME_PREFIX}" == "" ]] || [[ "${4}" != "" ]] ; then 343 | usage 344 | exit 5 345 | fi 346 | 347 | 348 | ensurePronto2Broadlink 349 | 350 | IRDB_PATH_LOWER="${IRDB_PATH,,}" 351 | if [[ "${IRDB_PATH_LOWER%.csv}" != "${IRDB_PATH_LOWER}" ]] ; then 352 | debug "path '${IRDB_PATH}' ends in .csv, downloading file..." 353 | irdbFileToYaml "${IRDB_PATH}" "${NAME_PREFIX}" "${MATCH_PATTERN}" 354 | else 355 | if [[ "${IRDB_PATH_LOWER%.conf}" != "${IRDB_PATH_LOWER}" ]] ; then 356 | ensureIrpTransmogrifier 357 | debug "path '${IRDB_PATH}' ends in .conf, assuming a lirc conf, downloading file..." 358 | lircFileToYaml "${IRDB_PATH}" "${NAME_PREFIX}" "${MATCH_PATTERN}" 359 | else 360 | debug "path '${IRDB_PATH}' does not end in .csv, assuming it is a directory, reading contents..." 361 | irdbDirToYaml "${IRDB_PATH}" "${NAME_PREFIX}" "${MATCH_PATTERN}" 362 | fi 363 | fi 364 | --------------------------------------------------------------------------------