Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept node name and location changes from outside UI #3591

Closed
spudwebb opened this issue Feb 9, 2024 · 22 comments · Fixed by #3592
Closed

Intercept node name and location changes from outside UI #3591

spudwebb opened this issue Feb 9, 2024 · 22 comments · Fixed by #3592
Assignees
Labels
enhancement New feature or request

Comments

@spudwebb
Copy link
Contributor

spudwebb commented Feb 9, 2024

I'm creating a ZWave driver for HomeSeer based on ZWave JS UI and using the ZWaveJS.NET library to communicate with the ZWave JS server.
I want to be able to update the name and location of a node so that when those values are updated within HomSseer they are also updated in ZWaveJS UI.
To do that I tried to use the ZWaveNode.SetName() and ZWaveNode.SetLocation() methods of the .NET library which correctly set the values in the ZWaveJS cache (in store/xxxxxxxx.values.jsonl), but it seems that ZWave JS UI completely ignore those values and uses its own instances of name and location that are saved in store/nodes.json.

So my question is: is there a way to update the name and location of a node displayed by ZWave JS UI using a command sent to the ZWave JS server?
Alternatively would it be possible to modify ZWave JS UI behavior so that either
(a) if there is no name/location in nodes.json then it uses the name and location from the ZWave JS cache
or
(b) add a setting that will force ZWave JS UI to always use the name and location from the ZWave JS cache

Related discussion zwave-js/ZWaveJS.NET#60

@spudwebb spudwebb added the question Further information is requested label Feb 9, 2024
@robertsLando
Copy link
Member

@spudwebb Problem is that actually I have no way to detect that node name and location changed on driver so that's why you don't see it there, if you restart the application you probably will see it correctly

@spudwebb
Copy link
Contributor Author

spudwebb commented Feb 9, 2024

@robertsLando
The driver uses the ValueID from the "Node Naming and Location" command class even if the node does not supports this class, so when I update the values the following events are emitted by the driver:

2024-02-09 09:00:16.640 INFO Z-WAVE: [Node 005] Value added 5-119-0-name => My Test Dimmer
2024-02-09 09:00:16.641 INFO Z-WAVE: [Node 005] Value updated: 119-0-name MyDimmer => My Test Dimmer

and it seems that ZWave JS UI get this info because it creates a "Node Naming and Location v0" CC with the name and location values:
image

but after a restart of the application you can see that this CC is gone, and the name and location fields are still not populated:

image

The device used for these screenshots does NOT support the "Node Naming and Location" command class

@robertsLando
Copy link
Member

The driver uses the ValueID from the "Node Naming and Location" command class even if the node does not supports this class

I didn't know about that. If so I could certainly catch those events to upate cached node name and location. Let me get a confirmation from @AlCalzone

@robertsLando robertsLando changed the title How to update local name and location of a node? Intercept node name and location changes from outside UI Feb 9, 2024
@robertsLando robertsLando added enhancement New feature or request and removed question Further information is requested labels Feb 9, 2024
@AlCalzone
Copy link
Member

AlCalzone commented Feb 9, 2024

That's correct. The bit about the value IDs vanishing is awkward though, I may have to rethink that.

@robertsLando
Copy link
Member

@spudwebb Could you give a try to #3592?

@spudwebb
Copy link
Contributor Author

spudwebb commented Feb 9, 2024

@robertsLando I tested the SYNC-NODE-NAME-LOC branch, and the fix only works for node that supports the "Node Naming and Location" CC. Name and Location of nodes that do not support it remain blank after a name or location update on the driver.

@robertsLando
Copy link
Member

@AlCalzone What is the behaviour when node doens't support name/location CC? Do you still list that cc in defined valueIds or do you emit the 'node added' event? If none of this that's the problem, I actually subscribe valueId observers on node ready and on value added events, if you only emit value changed I don't subscribe to it

@AlCalzone
Copy link
Member

AlCalzone commented Feb 12, 2024

getDefinedValueIDs should only return value IDs for CCs that are supported by the device.

I think you should ignore the Node Naming and Location CC in the list of value IDs (since you already have a dedicated UI for those properties) and instead read node.name / node.location for populating and subscribe to value added/updated/removed events for NodeNamingAndLocationCCValues.name.id and NodeNamingAndLocationCCValues.location.id for updating the naming UI.

@robertsLando
Copy link
Member

robertsLando commented Feb 12, 2024

@spudwebb try PR now

@spudwebb
Copy link
Contributor Author

@robertsLando , still not working, I don't see any name or location in the UI even though they are set on the driver side. And now it isn't working either for nodes that support name/location CC.

@robertsLando
Copy link
Member

robertsLando commented Feb 13, 2024

Ops, typo. Try now sorry. I successfully tested this working by using driver function to emulate a change of node name:

const node = driver.controller.nodes.get(78);
node.name = "Test"

When I run this I see the observer triggers and the name updates on UI too

@spudwebb
Copy link
Contributor Author

This is working well now. Thank you!

@robertsLando
Copy link
Member

Thanks for the feedback! Merging now

@spudwebb
Copy link
Contributor Author

@robertsLando, I'm reopening this because it seems that it doesn't work the first time I set the name and location for a node, in this case the driver emit some "Value added" events which does not trigger the renaming in UI

2024-02-19 13:42:40.018 INFO Z-WAVE: [Node 084] Value added: 119-0-name => HomeSeer Technologies HS-MS100+
2024-02-19 13:42:40.026 INFO Z-WAVE: [Node 084] Value added: 119-0-location => loc1

if I set again the same name and location for the same node, now "Value updated" events are emitted and it works

2024-02-19 13:42:40.036 INFO Z-WAVE: [Node 084] Value updated: 119-0-name HomeSeer Technologies HS-MS100+ => HomeSeer Technologies HS-MS100+
2024-02-19 13:42:40.043 INFO Z-WAVE: [Node 084] Value updated: 119-0-location loc1 => loc1

@robertsLando
Copy link
Member

@spudwebb Could you try this: #3612?

@spudwebb
Copy link
Contributor Author

@robertsLando it works as expected now thanks!

Not related but I wanted to mention it: on my windows machine when I try to run "npm run build" as stated in the docs I get the following error:

> [email protected] build
> npm-run-all 'build:*'

ERROR: Task not found: "'build:*'"

So my workaround was to run the 2 build commands separately and it worked:

npm run build:server
npm run build:ui

@robertsLando
Copy link
Member

robertsLando commented Feb 22, 2024

Sorry @spudwebb I missed your message, I think you may forgot to install dev dependencies? What are the steps you do to setup your repository? You should run npm install as very first command

@spudwebb
Copy link
Contributor Author

I followed the exact instructions found here: https://zwave-js.github.io/zwave-js-ui/#/getting-started/other-methods?id=nodejs-or-pkg-version
So, yes I ran npm install before running npm run build:

image

@AlCalzone
Copy link
Member

Might be a Windows thing with the single quotes.

@robertsLando
Copy link
Member

robertsLando commented Mar 4, 2024

@spudwebb That's really strange because it's exactly what I do on my side, it could be it's a windows issue? I'm not aware of any issue using npm-run-all package on windows BTW it should work cross platform

@spudwebb
Copy link
Contributor Author

spudwebb commented Mar 4, 2024

yes it looks like it's a windows issue with the single quotes. If I remove the single quotes for the build target in package.json it works as expected:

`"build": "npm-run-all build:*",`

@robertsLando
Copy link
Member

Ok I think there is no issue in removing it on my side too, thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants