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

Example of State Request and State methods #3

Open
lordofscripts opened this issue Nov 1, 2023 · 1 comment
Open

Example of State Request and State methods #3

lordofscripts opened this issue Nov 1, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@lordofscripts
Copy link

I noticed the documentation doesn't have any example of a State Request. Browsing through the code I noticed there was a structure for state requests. I think it would be nice to have a couple of methods for State() such as GetPoweredState() and IsConnected(). I managed to get the information this way:

	stateRequest := c.Client.Device(c.Address, c.Model).State()
	// {Code:200 Message:Success Data:{Device:..... Model:H5083 Properties:[map[online:true] map[powerState:off]] Devices:[]}}
	rsp, err := c.Client.Run(stateRequest)	// govee.GoveeResponse
	if rsp.Code != 200 {
		err = fmt.Errorf("State request failed: %q", rsp.Message)
	} else {
		fmt.Println("\tMAC    :", rsp.Data.Device)
		fmt.Println("\tModel  :", rsp.Data.Model)
		fmt.Println("\tOnline :", rsp.Data.Properties[0]["online"])
		fmt.Println("\tPowered:", rsp.Data.Properties[1]["powerState"])
	}
	return err

But I am ot sure if that is the proper way, especially the use of Data. Devices[]. I only have ONE Govee device so not much I can experiment with.

Other than that I am pretty satisfied, thanks for sharing this useful library. I know there are others but I tried this one and liked it, so it is the one I am using in my pet home project.

@Grant3W
Copy link
Member

Grant3W commented Nov 15, 2023

Hey! Thanks for checking out the package. They're very good points. I'm going to make a start on some additional helpers for state as you mentioned.

I'm also going to add built-in checking for the code returned from the Govee API, so theres no need to manually check like you have in your example.

@Grant3W Grant3W added the enhancement New feature or request label Nov 15, 2023
@Grant3W Grant3W self-assigned this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants