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

Allow measured power to be updated via notification command #4546

Merged

Conversation

dshokouhi
Copy link
Member

@dshokouhi dshokouhi commented Aug 1, 2024

Summary

Implements: #3290

example service call:

service: notify.mobile_app_pixel_8_pro
data:
  message: command_ble_transmitter
  data:
    command: ble_set_measured_power
    ble_measured_power: "-10"

The field is validated that its not blank and that it is a negative number

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#1086

Any other notes

FCM PR: home-assistant/mobile-apps-fcm-push#150

@jpelgrom
Copy link
Member

jpelgrom commented Aug 3, 2024

in some cases the notification will post on the device, in other cases the setting may revert to default

Why have it behave differently, instead of always ignoring it (which is the default behavior with notification commands for invalid values)?

@dshokouhi
Copy link
Member Author

in some cases the notification will post on the device, in other cases the setting may revert to default

Why have it behave differently, instead of always ignoring it (which is the default behavior with notification commands for invalid values)?

Added a check to make sure that doesn't happen, should be good now :)

@jpelgrom
Copy link
Member

jpelgrom commented Aug 5, 2024

I'm not sure I follow.

(data[DeviceCommandData.BLE_MEASURED_POWER]?.toIntOrNull() ?: BluetoothSensorManager.DEFAULT_MEASURED_POWER_AT_1M) < 0

will still use a different value if it cannot be parsed to an int, instead of rejecting/ignoring the command.

@dshokouhi
Copy link
Member Author

That was why i added the check before to capture any other bad value, added toIntOrNull because wanted to avoid a crash. I tested with teh following

  • negative numbers - works
  • positive numbers - posts notification
  • alphanumeric - posts notification
  • blank - posts notification

@jpelgrom
Copy link
Member

jpelgrom commented Aug 5, 2024

But why not do toIntOrNull() != null before instead of this convoluted check? The orNull is literally there for bad values.

And even if there is a bad (positive) value, it is still set as you don't change the value in line 160?

data[NotificationData.COMMAND] == DeviceCommandData.BLE_SET_MEASURED_POWER &&
    (
        data[DeviceCommandData.BLE_MEASURED_POWER].toIntOrNull() != null && data[DeviceCommandData.BLE_MEASURED_POWER]?.toInt() < 0
        )

@jpelgrom
Copy link
Member

jpelgrom commented Aug 5, 2024

I see my comment is inconsistent with current behavior - invalid changed to something valid for UUID/major/minor.

DeviceCommandData.BLE_SET_MAJOR -> data[DeviceCommandData.BLE_MAJOR]
?: BluetoothSensorManager.DEFAULT_BLE_MAJOR

But that is the exception to the default which ignores the command if invalid (in check):

(!data[DeviceCommandData.BLE_ADVERTISE].isNullOrEmpty() && data[DeviceCommandData.BLE_ADVERTISE] in DeviceCommandData.BLE_ADVERTISE_COMMANDS) ||

@dshokouhi
Copy link
Member Author

Your check is simpler and for some reason I did not consider it, lets go with that as its easier to read :)

@jpelgrom jpelgrom merged commit 05c71ca into home-assistant:master Sep 10, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional notification type to change the reference power transmitted with iBeacon advertisements
2 participants