Skip to content

Commit

Permalink
Warn about unexpected behaviour of new Bridge in a Subflow #393
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaquu committed Jun 30, 2021
1 parent 85dc377 commit c820fbe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
16 changes: 16 additions & 0 deletions build/nodes/nrchkb.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<style>
.alert {
position: relative;
padding: .75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: .25rem;
margin-right: 60px;
}
.alert-warning {
color: #856404;
background-color: #fff3cd;
border-color: #ffeeba;
}
</style>

<script type="text/javascript">
const initExperimental = function () {
//NRCHKB Custom Characteristics
Expand Down
38 changes: 36 additions & 2 deletions build/nodes/service.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</select>
</div>
<div id="isOnBridge">
<div id="isBridgeInSubflow" class="alert alert-warning" role="alert">
Read more <b><a href="#" id="bridgeInSubflowNotice">here</a></b> about adding Bridge in a Subflow.
</div>
<div class="form-row" style="height: 34px;">
<label for="node-input-bridge">
<i class="fa fa-rocket"></i>
Expand Down Expand Up @@ -534,13 +537,23 @@ <h2 id="toc_8">Characteristic Properties</h2>
}

let isOnBridgeDiv = $('#isOnBridge')
let isBridgeInSubflow = $('#isBridgeInSubflow')
let isAccessoryDiv = $('#isAccessory')

const inSubflow = !!RED.nodes.subflow(node.z)

selectHostType
.change(function () {
if (selectHostType.val() == 0) {
isAccessoryDiv.hide()
isOnBridgeDiv.show()

if (inSubflow) {
isBridgeInSubflow.show()
} else {
isBridgeInSubflow.hide()
}

$("#node-input-accessoryId").val("_ADD_");
} else {
isOnBridgeDiv.hide()
Expand Down Expand Up @@ -595,8 +608,6 @@ <h2 id="toc_8">Characteristic Properties</h2>

const selectParentService = $('#node-input-parentService')

const inSubflow = !!RED.nodes.subflow(node.z)

const candidateNodes = RED.nodes.filterNodes({
type: 'homekit-service',
})
Expand Down Expand Up @@ -672,6 +683,29 @@ <h2 id="toc_8">Characteristic Properties</h2>
accessoryOption.text(accessoryOption.text() + " already used by " + n.name)
}
})

isBridgeInSubflow.find('#bridgeInSubflowNotice').on("click", function() {
$('<div>')
.css({ maxHeight: '80%' })
.html("<ul>" +
"<li>If a Bridge is created from within the Subflow editor, a new Bridge will be created each time the Subflow is used.</li>" +
"<li>If a Bridge is created from the normal flows screen then each HomeKit item in a Subflow will simply be added to the existing (single) Bridge.</li>" +
"<li>Visit our <b><a href=\"https://nrchkb.github.io/wiki/introduction/service-node/#bridge\">wiki</a></b> for more information.</li>" +
"</ul>")
.dialog({
draggable: true,
modal: true,
resizable: false,
width: 'auto',
title: 'Important Notice',
minHeight: 75,
buttons: {
Close: function () {
$(this).dialog('destroy')
}
}
})
})
},
oneditsave: function () {
let node = this
Expand Down
4 changes: 2 additions & 2 deletions src/lib/HAPHostNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ module.exports = (RED: NodeAPI, hostType: HostType) => {
}
}

self.accessoryCategory = ((self.hostType == HostType.BRIDGE
self.accessoryCategory = (self.hostType == HostType.BRIDGE
? HapCategories.BRIDGE
: self.config.accessoryCategory) as unknown) as Categories
: self.config.accessoryCategory) as unknown as Categories

self.published = false
self.bridgeUsername = macify(self.id)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module.exports = function (RED: NodeAPI) {
.sort()
.filter((x) => parseInt(x) >= 0)
.forEach((key) => {
const keyNumber = (key as unknown) as number
const keyNumber = key as unknown as number
accessoryCategoriesData[keyNumber] = HapCategories[keyNumber]
})

Expand Down
4 changes: 2 additions & 2 deletions src/test/lib/HAPBridgeNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ describe('HAPHostNode', function () {
})

it('null string macify should fail', function (done) {
const stringToMacify = (null as unknown) as string
const stringToMacify = null as unknown as string
should.throws(() => {
HAPHostNode.macify(stringToMacify)
}, 'nodeId cannot be empty in macify process')
done()
})

it('undefined string macify should fail', function (done) {
const stringToMacify = (undefined as unknown) as string
const stringToMacify = undefined as unknown as string
should.throws(() => {
HAPHostNode.macify(stringToMacify)
}, 'nodeId cannot be empty in macify process')
Expand Down

0 comments on commit c820fbe

Please sign in to comment.