Skip to content

Conversation

@RenierM26
Copy link
Contributor

@RenierM26 RenierM26 commented Jun 8, 2021

-Added discovery method.
-All updates are now handled by single advertisement scan.

This should allow discovery and coordinator based updates in hass integration.

model number (first byte of 16b service data):
"c" = Curtain
"H" = WoHand or otherwise known as bot.
"T" = woSensorTH or otherwise known as temp/humidity sensor. (I don't have one and can't test the output)

Returns python dict with all device data of type with single scan.
Example of single curtain (json formated - easier to format in notepad ++):

"fd8082999999": {
	"mac_address": "fd:80:82:99:99:99",
	"Flags": "06",
	"Manufacturer": "5900fd8082c51181",
	"Complete 128b Services": "cba20d00-224d-11e6-9fb8-0002a5d5c51b",
	"data": {
		"calibration": true,
		"battery": 57,
		"position": 98,
		"lightLevel": 2,
		"rssi": -68
	},
	"model": "c",
	"modelName": "WoCurtain"
},

Returns python dict with all device data of type with single scan.
Example of returned data for switchbot bot(json formatted - easier to format in notepad ++):

"e78943999999": {
	"mac_address": "e7:89:43:99:99:99",
	"Flags": "06",
	"Manufacturer": "5900e78943d9fe7c",
	"Complete 128b Services": "cba20d00-224d-11e6-9fb8-0002a5d5c51b",
	"data": {
		"switchMode": true,
		"isOn": true,
		"battery": 91,
		"rssi": -71
	},
	"model": "H",
	"modelName": "WoHand"
},

@RenierM26
Copy link
Contributor Author

RenierM26 commented Jun 8, 2021

Should close #16
and
#17

@RenierM26 RenierM26 marked this pull request as draft June 10, 2021 16:01
@RenierM26 RenierM26 marked this pull request as ready for review June 11, 2021 16:59
@RenierM26 RenierM26 marked this pull request as draft June 16, 2021 08:28
@RenierM26 RenierM26 marked this pull request as ready for review June 16, 2021 14:50
@RenierM26
Copy link
Contributor Author

Hi @Danielhiversen,

I'm done with this pull request. Could you please review if you get a chance?

Thank you.

Copy link
Collaborator

@Danielhiversen Danielhiversen left a comment

Choose a reason for hiding this comment

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

Some initial comments.

@Jan108 Any comments? time_between_update_command will be removed

@Danielhiversen
Copy link
Collaborator

For later, please do not include any formatting changes. Makes it difficult to review and see actual changes.

RenierM26 and others added 2 commits June 16, 2021 18:02
Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net>
Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net>
@RenierM26
Copy link
Contributor Author

I have a working prototype Hass integration that makes use of a coordinator to update states of all devices (I have >8 switchbots) and it updates without any btle errors.

This might help to indicate the logic behind the changes?

https://github.com/RenierM26/ha-switchbot-curtain/tree/main/custom_components/switchbot-curtain

Once I've managed to add "send commands" to the coordinator I will submit pull requests on hass. BLE is a real pain to figure out ways to properly time all adapter commands. (you can literally only issue 1 command at a time with the pygatt based python libraries)

@Danielhiversen
Copy link
Collaborator

I think you should make a DataHandler class with functions:
discover -> returns list of Switchbot and SwitchbotCurtain
get_bots -> returns list of Switchbot
get_curtains -> returns list of SwitchbotCurtain

Would that make sense for you?

@RenierM26
Copy link
Contributor Author

I think you should make a DataHandler class with functions:
discover -> returns list of Switchbot and SwitchbotCurtain
get_bots -> returns list of Switchbot
get_curtains -> returns list of SwitchbotCurtain

Would that make sense for you?

No problem. Created a new class for these and modified method in SwitchbotDevice for single MAC scan.

@Jan108
Copy link
Contributor

Jan108 commented Jun 16, 2021

The time_between_update_command prevented the reading of false data from the curtain (I can only asume it's a problem for all), this happens if you read the service data while the curtain is moving. The position attribute isn't correct at this moment.

When with the new code this is no longer a problem we can remove it. But if this still can happen, I would say the library should take care of this and not hass or the libaray user.

@RenierM26
Copy link
Contributor Author

The time_between_update_command prevented the reading of false data from the curtain (I can only asume it's a problem for all), this happens if you read the service data while the curtain is moving. The position attribute isn't correct at this moment.

When with the new code this is no longer a problem we can remove it. But if this still can happen, I would say the library should take care of this and not hass or the libaray user.

Hi @Jan108 and @Danielhiversen ,

Pretty sure I solved this problem with the binary AND which I found in the node-switchbot code. (Pesky things these binary trees)

Just busy testing a few conditions to confirm.

@RenierM26
Copy link
Contributor Author

Hi @Jan108 and @Danielhiversen,

If reading of service data occur while the curtain is moving, it literately returns the curtain position at that time. Battery and other data is also returned correctly.

@RenierM26
Copy link
Contributor Author

Hi @Danielhiversen,

Think I addressed all of your suggestions. Please have a look when you get a chance?

Thank you.

Copy link
Collaborator

@Danielhiversen Danielhiversen left a comment

Choose a reason for hiding this comment

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

Great. Thanks 👍

I do not think GetSwitchbotDevices is a very good name, but I do not have any better suggestion :)

@Danielhiversen Danielhiversen merged commit 590b58a into sblibs:master Jun 19, 2021
@88fingerslukee
Copy link

Great. Thanks 👍

I do not think GetSwitchbotDevices is a very good name, but I do not have any better suggestion :)

SwitchbotDeviceDiscovery?

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.

4 participants