Skip to content

Commit

Permalink
fix: entity names with empty location
Browse files Browse the repository at this point in the history
Fixes #162
  • Loading branch information
robertsLando committed Jan 12, 2021
1 parent 277b542 commit 9605083
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/usage/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ Gateway settings:
- **Use nodes name instead of numeric nodeIDs**: When gateway type is `ValueId` use this flag to force to use node names instead of node ids in topic.
- :star:**Hass discovery**:star:: Enable this to automatically create entities on Hass using MQTT autodiscovery (more about this [here](#robot-home-assistant-integration-beta))
- **Discovery Prefix**: The prefix to use to send MQTT discovery messages to HASS
- **Entity name template**: Custom Entity name based on placeholders. Default is `%loc-%n_%o`
- **Entity name template**: Custom Entity name based on placeholders. Default is `%ln_%o`
- `%ln`: Node location with name `<location-?><name>`
- `%n`: Node Name
- `%loc`: Node Location
- `%pk`: valueId property key (fallback to device type)
Expand Down
3 changes: 2 additions & 1 deletion lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ function setDiscoveryValue (payload, prop, node) {
* @param {string} entityTemplate the entity template from configuration
*/
function getEntityName (node, valueId, cfg, entityTemplate) {
entityTemplate = entityTemplate || '%loc-%n_%o'
entityTemplate = entityTemplate || '%ln_%o'
// when getting the entity name of a device use node props
let propertyKey = cfg.type
let propertyName = cfg.type
Expand All @@ -682,6 +682,7 @@ function getEntityName (node, valueId, cfg, entityTemplate) {

return entityTemplate
.replace(/%nid/g, NODE_PREFIX + node.id)
.replace(/%ln/g, getNodeName(node))
.replace(/%loc/g, node.loc || '')
.replace(/%pk/g, propertyKey)
.replace(/%pn/g, propertyName)
Expand Down
4 changes: 3 additions & 1 deletion src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@
</v-flex>
<v-flex xs6 v-if="gateway.hassDiscovery">
<div>
Default: <code>%loc-%n_%o</code> <br />-
Default: <code>%ln_%o</code><br />
-<code>%ln</code>: Node location with name
(<code>&lt;location-?&gt;&lt;name&gt;</code>)<br />-
<code>%nid</code>: Node ID <br />- <code>%n</code>:
Node Name <br />- <code>%loc</code>: Node Location
<br />- <code>%pk</code>: valueId property key
Expand Down

0 comments on commit 9605083

Please sign in to comment.