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

fix reversed bot state reporting #207

Merged

Conversation

grelca
Copy link

@grelca grelca commented Dec 6, 2023

♻️ Current situation

closes #206
bot state is being reported backwards, the bot broadcasts 0 when when bot switch is on and 1 when it is off.

💡 Proposed solution

update the advertising parser to recognize a bit value of 0 as the switch state being on, and a value of 1 as the switch state being off.

⚙️ Release Notes

Fixes an issue where SwitchBot bot state was reported incorrectly.

Testing

don't see any automated test framework to add to or update, but validated state was reported correctly in node repl that state value was reported correctly

testing output bot started off, i toggled it on then off during test. state was reported correctly each time
> var switchbot = require('./lib/switchbot')
undefined
> var s = new switchbot()
undefined
> s.onadvertisement = console.log
[Function: log]
> s.startScan({ model: 'H' })
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 243,
  [Symbol(trigger_async_id_symbol)]: 6
}
> {
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -63,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -68,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -63,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -62,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -70,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -71,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -65,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -66,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -66,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -66,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -76,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -76,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -65,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -66,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -76,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -69,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 98
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -69,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: true,
    battery: 100
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -61,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: true,
    battery: 100
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -61,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: true,
    battery: 100
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -61,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -64,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -64,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -71,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -64,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}
{
  id: '265d16762bc91643c2ea93c9cc2b6a4f',
  address: 'ff:47:4d:2e:de:28',
  rssi: -64,
  serviceData: {
    model: 'H',
    modelName: 'WoHand',
    mode: true,
    state: false,
    battery: 99
  }
}

@donavanbecker donavanbecker merged commit 0f8ed75 into OpenWonderLabs:beta-1.9.2 Dec 6, 2023
@donavanbecker
Copy link
Collaborator

Thanks!

@donavanbecker
Copy link
Collaborator

I will get this into a homebridge-switchbot plugin as soon as i have time.

@donavanbecker donavanbecker mentioned this pull request Jan 5, 2024
donavanbecker added a commit that referenced this pull request Jan 5, 2024
## [1.10.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.10.0) (2024-1-5)

## What's Changed
- Fix reversed bot state reporting, Thanks [@grelca](https://github.com/grelca) [#207](#207)
- Add support for Curtain 3, Thanks [@tsia](https://github.com/tsia) [#209](#209)
- Housekeeping and update dependencies

**Full Changelog**: v1.9.1...v1.10.0
donavanbecker added a commit that referenced this pull request Jan 5, 2024
## [1.10.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.10.0) (2024-1-5)

## What's Changed
- Fix reversed bot state reporting, Thanks [@grelca](https://github.com/grelca) [#207](#207)
- Add support for Curtain 3, Thanks [@tsia](https://github.com/tsia) [#209](#209)
- Housekeeping and update dependencies

**Full Changelog**: v1.9.1...v1.10.0
donavanbecker added a commit that referenced this pull request Jan 5, 2024
- Fix reversed bot state reporting, Thanks [@grelca](https://github.com/grelca) [#207](#207)
- Add support for Curtain 3, Thanks [@tsia](https://github.com/tsia) [#209](#209)
- Housekeeping and update dependencies

**Full Changelog**: v1.9.1...v1.10.0
donavanbecker added a commit that referenced this pull request Jan 6, 2024
- Fix reversed bot state reporting, Thanks [@grelca](https://github.com/grelca) [#207](#207)
- Add support for Curtain 3, Thanks [@tsia](https://github.com/tsia) [#209](#209)
- Housekeeping and update dependencies

**Full Changelog**: v1.9.1...v1.10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants