lagunacomputer / homebridge-MotionSensor

HomeBridge HomeKit Plugin for arduino based PIR motion sensors
23 stars 14 forks source link

Package refactor #1

Closed metbosch closed 7 years ago

metbosch commented 7 years ago

Hi, Thanks for your investigations about this kind of sensors! I re-factored the module to be more flexible and handle the requests asynchronously. Also, I added a sample JSON file and listed all possible options in the README. I think that this changes can be useful for someone more. Thanks!

perote2000 commented 7 years ago

Just a small error, install command is incorrect in readme.md... should be sudo npm install -g homebridge-MotionSensor

metbosch commented 7 years ago

@perote2000, Thanks for the appointment! Did you test the master implementation and mine? Since there is no feedback from @lagunacomputer, I'm thinking about publishing my version in npm.

lagunacomputer commented 7 years ago

sorry this is the first time I have seen this, whats up?

lagunacomputer commented 7 years ago

to be honest with you, I'm not a programmer and barely understand how these changes work in github. I haven't messed with this plugin in almost a year, so I am going to assume you've made it better (thank you) and hit the big green Merge pull request button. thanks!

metbosch commented 7 years ago

@lagunacomputer The main idea of the changes is to avoid blocking the thread until the sensor response arrives back to the plugin. Thanks for merging, can you forward the changes to npm?

perote2000 commented 7 years ago

Ive tested both versions, both works, of course Ive updates to metbosch to support non blocking. I had to copy manually the missing modules that were not included on /opt/node/lib/node_modules/homebridge-MotionSensor/node_modules due the update uses another libraries. Once it became packaged in npn I thing it will include all needed dependencies.

Another important issue in both version is that none of these has been coded to support interval check time. both version only check for sensor once when homekit app starts. I'm newbie in javascript and nodejs, as far as I undertood there should be a callback and settimeout in order thar the "check_status" function call itself in N seconds....

lagunacomputer commented 7 years ago

i cant figure out why it wont update NPM. i downloaded the new changes from github, i must not be putting it in the correct folder or something. Does it have to be in the original folder to re-publish/update? here is my errors, if you know what I am doing wrong, let me know and i will get it posted asap thx

pi@pi:~/.homebridge/newnpm/homebridge-MotionSensor $ npm version major npm ERR! Linux 4.9.24+ npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "version" "major" npm ERR! node v4.3.2 npm ERR! npm v2.14.12

npm ERR! Git working directory not clean. npm ERR! M package.json npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR! /home/pi/.homebridge/newnpm/homebridge-MotionSensor/npm-debug.log

perote2000 commented 7 years ago

Ive never posted a package in npn... serching on google I found..

https://github.com/npm/npm/issues/6879 (use --force) https://stackoverflow.com/questions/673407/how-do-i-clear-my-local-working-directory-in-git (clean repos)

perhaps it may help....

2017-07-28 16:37 GMT-03:00 lagunacomputer notifications@github.com:

i cant figure out why it wont update NPM. i downloaded the new changes from github, i must not be putting it in the correct folder or something. here is my errors

pi@pi:~/.homebridge/newnpm/homebridge-MotionSensor $ npm version major npm ERR! Linux 4.9.24+ npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "version" "major" npm ERR! node v4.3.2 npm ERR! npm v2.14.12

npm ERR! Git working directory not clean. npm ERR! M package.json npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR! /home/pi/.homebridge/newnpm/homebridge-MotionSensor/npm-debug.log pi@pi:~/.homebridge/newnpm/homebridge-MotionSensor $ npm version minor npm ERR! Linux 4.9.24+ npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "version" "minor" npm ERR! node v4.3.2 npm ERR! npm v2.14.12

npm ERR! Git working directory not clean. npm ERR! M package.json npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR! /home/pi/.homebridge/newnpm/homebridge-MotionSensor/npm-debug.log

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lagunacomputer/homebridge-MotionSensor/pull/1#issuecomment-318743938, or mute the thread https://github.com/notifications/unsubscribe-auth/Acw0OThMHUmXPvPgFfjcVN8Z4vJqdTKkks5sSjiVgaJpZM4MjJE- .

lagunacomputer commented 7 years ago

ok i think i fixed it. what a friggin nightmare. try to download it from NPM now

https://www.npmjs.com/package/homebridge-MotionSensor

hopefully it will say version 3.0.0 or something besides 0.0.1.

Make sure to put your names in the credits somewhere if you want. thanks guys

lagunacomputer commented 7 years ago

note to self for next time:

cd .homebridge/homebridge-MotionSensor sudo git clone https://github.com/lagunacomputer/homebridge-MotionSensor.git ls -l sudo chmod 777 * sudo git add . git config --global user.name "lagunacomputer" sudo git commit sudo git config --global user.email "xxxx@gmail.com" sudo git commit sudo git clean -f -i -n sudo git clean -i sudo git clean -f sudo git clean -df ls sudo npm version major --force sudo npm login sudo npm publish

metbosch commented 7 years ago

@lagunacomputer Thanks for uploading the changes. @perote2000 As far as I know, homebridge is not able to update the status of an accessory in the clients (iPhone, ...). The clients request the status when they consider to homebridge which calls the getStatus function of the plugin. Therefore, the polled status from the sensor will not be directly shown in the clients. Moreover, asking the sensor status when a client whats to know it (current implementation) is a good approach for me.

perote2000 commented 7 years ago

Hi, but lights and Switches updates, for instance using cmdswitch2 plugin if I set interval it refresh in HomeKit, even if I change state of light outside the app.

Enviado desde mi iPhone

El 29 jul. 2017, a las 12:09, metbosch notifications@github.com escribió:

@lagunacomputer Thanks for uploading the changes. @perote2000 As far as I know, homebridge is not able to update the status of an accessory in the clients (iPhone, ...). The clients request the status when they consider to homebridge which calls the getStatus function of the plugin. Therefore, the polled status from the sensor will not be directly shown in the clients. Moreover, asking the sensor status when a client whats to know it (current implementation) is a good approach for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

perote2000 commented 7 years ago

But light switches like in cmdswitch2 updates status every interval seconds. Even if you change status outside HomeKit... it for instance check status and shows the new one on HomeKit. I'll try to modify your last implementation to support it (I'll learn JS first 😁)

Enviado desde mi iPhone

El 29 jul. 2017, a las 12:09, metbosch notifications@github.com escribió:

@lagunacomputer Thanks for uploading the changes. @perote2000 As far as I know, homebridge is not able to update the status of an accessory in the clients (iPhone, ...). The clients request the status when they consider to homebridge which calls the getStatus function of the plugin. Therefore, the polled status from the sensor will not be directly shown in the clients. Moreover, asking the sensor status when a client whats to know it (current implementation) is a good approach for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

lagunacomputer commented 7 years ago

check out the new github commits to homebridge-MotionSensor , the other guys may have figured out how to send real time updates with the new code

On Sat, Jul 29, 2017 at 2:59 PM, perote2000 notifications@github.com wrote:

But light switches like in cmdswitch2 updates status every interval seconds. Even if you change status outside HomeKit... it for instance check status and shows the new one on HomeKit. I'll try to modify your last implementation to support it (I'll learn JS first 😁)

Enviado desde mi iPhone

El 29 jul. 2017, a las 12:09, metbosch notifications@github.com escribió:

@lagunacomputer Thanks for uploading the changes. @perote2000 As far as I know, homebridge is not able to update the status of an accessory in the clients (iPhone, ...). The clients request the status when they consider to homebridge which calls the getStatus function of the plugin. Therefore, the polled status from the sensor will not be directly shown in the clients. Moreover, asking the sensor status when a client whats to know it (current implementation) is a good approach for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lagunacomputer/homebridge-MotionSensor/pull/1#issuecomment-318862393, or mute the thread https://github.com/notifications/unsubscribe-auth/ADqL6mEoLQbdQFLVvxiiGejYTuKjJEEsks5sS6tKgaJpZM4MjJE- .

-- Galen Wollenberg Laguna Computer 949-813-3691 lagunacomputer@gmail.com

metbosch commented 7 years ago

@lagunacomputer Where we can find the changes you mention? Can you paste the link here?

perote2000 commented 7 years ago

I think that lagunacomputer is talking about the changes you made.

Enviado desde mi iPhone

El 30 jul. 2017, a las 15:43, metbosch notifications@github.com escribió:

@lagunacomputer Where we can find the changes you mention? Can you paste the link here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

perote2000 commented 7 years ago

Another implementation is hhtp-motion-sensor, that starts a listener and the sensor push an event to homebridge (via hhtp connection), that implementation allows to sensor to perform a pull to send status of sensor (movement when a conn accours). Both are valid, but this implementation from my point of view needs a parameter to check state periodically, which is not currently happenging.

2017-07-30 15:43 GMT-03:00 metbosch notifications@github.com:

@lagunacomputer https://github.com/lagunacomputer Where we can find the changes you mention? Can you paste the link here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lagunacomputer/homebridge-MotionSensor/pull/1#issuecomment-318920955, or mute the thread https://github.com/notifications/unsubscribe-auth/Acw0Oc1ca8OTRIsuzna6QGJXHSXPc3Wfks5sTM7qgaJpZM4MjJE- .

lagunacomputer commented 7 years ago

https://www.npmjs.com/package/homebridge-MotionSensor https://github.com/lagunacomputer/homebridge-MotionSensor

metbosch commented 7 years ago

@lagunacomputer I can only see my changes in your links. Take a look at: https://github.com/lagunacomputer/homebridge-MotionSensor/pull/3, I think that I get it. I didn't know the updateState method of homebridge (@perote2000 thanks for the appointment). If it is okey for you, I added myself in the contributors list and increased the version in package.json (so you should be able to publish the package without problems).

lagunacomputer commented 7 years ago

great thanks sir

perote2000 commented 7 years ago

Great news... I`ll test that tonight...

2017-07-31 14:07 GMT-03:00 metbosch notifications@github.com:

@lagunacomputer https://github.com/lagunacomputer I can only see my changes in your links. Take a look at: #3 https://github.com/lagunacomputer/homebridge-MotionSensor/pull/3, I think that I get it. I didn't know the updateState method of homebridge ( @perote2000 https://github.com/perote2000 thanks for the appointment). If it is okey for you, I added myself in the contributors list and increased the version in package.json (so you should be able to publish the package without problems).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lagunacomputer/homebridge-MotionSensor/pull/1#issuecomment-319132595, or mute the thread https://github.com/notifications/unsubscribe-auth/Acw0OQRjmX3yiFQEvFb-AQ0VCj91NxE6ks5sTgnWgaJpZM4MjJE- .

perote2000 commented 7 years ago

Worked great! Tested last light...

Enviado desde mi iPhone

El 31 jul. 2017, a las 14:07, metbosch notifications@github.com escribió:

@lagunacomputer I can only see my changes in your links. Take a look at: #3, I think that I get it. I didn't know the updateState method of homebridge (@perote2000 thanks for the appointment). If it is okey for you, I added myself in the contributors list and increased the version in package.json (so you should be able to publish the package without problems).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.