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

Add batteryMask for iBeacons #337

Merged
merged 2 commits into from
Nov 9, 2020
Merged

Conversation

PeteBa
Copy link
Contributor

@PeteBa PeteBa commented Nov 7, 2020

Describe the change
Some iBeacons provide battery level information in the major/minor fields. This PR adds a batteryMask option to identify the battery level and, if present, create a new sensor entity so that the information can be sent to, for example, Home Assistant. The mask operates on a 32bit field using major as the high two bytes and minor as the low two bytes.

So, for example, with some Jaylee beacons that provide 0-100 value in the high byte of the minor field, you can use batteryMask: "0x0000FF00" to extract the information. You can add the option at the BLE module or beacon level (via tagOverride).

Let me know if this is useful and I can adjust docs/test as needed.

Checklist
If you changed code:

  • Tests run locally and pass (npm test)
  • Code has correct format (npm run format)

If you added a new integration:

  • Documentation page added in docs/integrations/
  • Page linked in docs/.vuepress/config.js and docs/integrations/README.md

Additional information
Partially addresses #160

@PeteBa PeteBa requested a review from mKeRix as a code owner November 7, 2020 13:47
@codecov
Copy link

codecov bot commented Nov 7, 2020

Codecov Report

Merging #337 (a03c205) into master (526edf8) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #337      +/-   ##
==========================================
+ Coverage   91.65%   91.80%   +0.14%     
==========================================
  Files          86       86              
  Lines        1846     1879      +33     
  Branches      227      236       +9     
==========================================
+ Hits         1692     1725      +33     
  Misses        151      151              
  Partials        3        3              
Flag Coverage Δ
unittests 91.80% <100.00%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ons/bluetooth-classic/bluetooth-classic.service.ts 97.79% <100.00%> (ø)
...low-energy/bluetooth-low-energy-presence.sensor.ts 100.00% <100.00%> (ø)
...luetooth-low-energy/bluetooth-low-energy.config.ts 100.00% <100.00%> (ø)
...uetooth-low-energy/bluetooth-low-energy.service.ts 100.00% <100.00%> (ø)
src/integrations/bluetooth-low-energy/i-beacon.ts 100.00% <100.00%> (ø)
...rations/bluetooth-low-energy/new-distance.event.ts 100.00% <100.00%> (ø)
.../integrations/room-presence/room-presence.proxy.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 526edf8...a03c205. Read the comment docs.

Copy link
Owner

@mKeRix mKeRix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool addition! This complements your major/minor mask feature well. In addition to the comments on the current code it would also be great if you could write some tests for the new functionality and add the batteryMask option to the relevant tables in bluetooth-low-energy.md.

Copy link
Owner

@mKeRix mKeRix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I will get this merged and released soon, just want to put one more thing into the release as well.

@mKeRix mKeRix merged commit ac9717f into mKeRix:master Nov 9, 2020
github-actions bot pushed a commit that referenced this pull request Nov 9, 2020
# [2.12.0](v2.11.3...v2.12.0) (2020-11-09)

### Features

* **bluetooth-low-energy:** add batteryMask for iBeacons ([#337](#337)) ([ac9717f](ac9717f))
* generate heatmaps w/o native dependencies ([ee8310c](ee8310c))
@github-actions
Copy link

github-actions bot commented Nov 9, 2020

🎉 This PR is included in version 2.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@PeteBa PeteBa deleted the add-ibeacon-battery branch November 11, 2020 00:15
@liamstears
Copy link

Hey PeyeBa, where did you get the Jaylee beacons you mention? I would like to buy the same beacons so I know they will work correctly and do what I need to do...

@PeteBa
Copy link
Contributor Author

PeteBa commented Aug 19, 2021

The ones I have were distributed by Ankhmaway and Jaalee. I bought mine many years ago from a UK based retailer ibeaconzone. I went with the IB001M for my keyring as it is pretty small and a bunch of IB004N that are a bit bigger but with longer range for the visitors/cleaner/gardener/... Looks like the seller has some stock (IB004N) but out-of-stock (IB001M). A quick google shows sporadic hits (alibaba, etc) so may be difficult to source locally. I do see there is a Jaalee store that has similar for sale here.

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

Successfully merging this pull request may close these issues.

None yet

3 participants