govee api documentation

21
Govee API Documentation Release 2.0.0 Thomas Reiser May 24, 2020

Upload: others

Post on 24-Jan-2022

49 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Govee API Documentation

Govee API DocumentationRelease 2.0.0

Thomas Reiser

May 24, 2020

Page 2: Govee API Documentation
Page 3: Govee API Documentation

Contents:

1 Govee API 11.1 Message to Govee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Approved device support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Not yet implemented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.5 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Installation 32.1 Stable release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 From sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Usage 5

4 Contributing 94.1 Types of Contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.2 Get Started! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.3 Pull Request Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.4 Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.5 Deploying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 Credits 135.1 Development Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.2 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6 History 156.1 2.0.0 (2020-05-24) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.2 1.3.0 (2020-05-17) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.3 1.2.0 (2020-05-13) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.4 1.1.0 (2020-05-12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.5 1.0.0 (2020-05-08) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

7 Indices and tables 17

i

Page 4: Govee API Documentation

ii

Page 5: Govee API Documentation

CHAPTER 1

Govee API

Simple and minimal Govee Home API client to control Govee smart devices.

• Free software: Apache 2.0 License

• Documentation: https://govee_api.readthedocs.io.

pip install -r requirements_dev.txt

1.1 Message to Govee

We all love your products but unfortunately there is no public API. Thus, we cannot control the devices we have pur-chased in our own smart home environments. I have created this library so that I can control my devices easily withoutthe Govee app and to help others doing this. Nobody wants to harm you, your server infrastructure or anything oranybody else. In case you cannot accept my code to be public, please send me an e-mail to [email protected] I will immediately shut down this repository and will delete all artifacts from PyPi.

1.2 Features

• Control Govee IOT smart devices (Bulbs, LED strips)

1

Page 6: Govee API Documentation

Govee API Documentation, Release 2.0.0

1.3 Approved device support

Device SKU Approved sinceBulbsH6001 2.0.0LED stripsH6113 2.0.0H6159 1.0.0H6163 1.0.0String lights-none yet-

Please test your own devices with the API and tell me the results! In case something did not work, please provide methe RAW JSON data received via the new device + device update events.

1.4 Not yet implemented

• String light support

• Bluetooth-only color modes (Music, Scene, DIY)

• Bluetooth events sent from devices (are there any?)

1.5 Usage

See docs/usage.rst or testclient.py

2 Chapter 1. Govee API

Page 7: Govee API Documentation

CHAPTER 2

Installation

2.1 Stable release

To install Govee API, run this command in your terminal:

$ pip install govee_api

This is the preferred method to install Govee API, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

2.2 From sources

The sources for Govee API can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/thomasreiser/govee_api

Or download the tarball:

$ curl -OJL https://github.com/thomasreiser/govee_api/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

3

Page 8: Govee API Documentation

Govee API Documentation, Release 2.0.0

4 Chapter 2. Installation

Page 9: Govee API Documentation

CHAPTER 3

Usage

To use Govee API in a project:

from govee_api import api, deviceimport timeimport colour

def main():# Create Govee client and configure event handlersgovee_cli = api.Govee('your_email', 'your_password', 'your_client_id_or_EMPTY')# BEWARE: This will create a new Govee Client ID with every login. It is

→˓recommended to provide an existing client ID# within the `Govee` contructor. You can fetch your generated client ID via

→˓`govee.client_id` after your successful login

# Event raised when a new device is discoveredgovee_cli.on_new_device = _on_new_device

# Event raised when a device status was updatedgovee_cli.on_device_update = _on_device_update

# Login to Goveegovee_cli.login()

# Print out the used client IDprint('Current client ID is: {}'.format(govee_cli.client_id))

# Fetch known devices from servergovee_cli.update_device_list()

print('Preparing for action :-)')# Don't do this in real life. Use the callbacks the client provides to you!time.sleep(10)

# Loop over all devices

(continues on next page)

5

Page 10: Govee API Documentation

Govee API Documentation, Release 2.0.0

(continued from previous page)

for dev in govee_cli.devices.values():if dev.connected:

print('Fun with device {} ...'.format(dev.name))

# Turn on devicedev.on = True

# Wait a secondtime.sleep(1)

# Save initial brightnessbrightness_backup = dev.brightness

# Set brightness to 50%dev.brightness = 0.5

# Wait a secondtime.sleep(1)

# Set brightness to 100%dev.brightness = 1.0

# Wait a secondtime.sleep(1)

if isinstance(dev, device.GoveeRgbLight):# Save initial colorcolor_backup = dev.color

# Set color temperature to 2100 kelvin (warm white)dev.color_temperature = 2100

# Wait a secondtime.sleep(1)

# Set color to greendev.color = colour.Color('green')

# Wait a secondtime.sleep(1)

# Set color to reddev.color = (255, 0, 0)

# Wait a secondtime.sleep(1)

# Set color to dodgerbluedev.color = colour.Color('dodgerblue')

# Wait a secondtime.sleep(1)

# Restore colorif color_backup:

dev.color = color_backup

(continues on next page)

6 Chapter 3. Usage

Page 11: Govee API Documentation

Govee API Documentation, Release 2.0.0

(continued from previous page)

# Wait a secondtime.sleep(1)

# Restore initial brightnessdev.brightness = brightness_backup

# Wait a secondtime.sleep(1)

# Turn the device offdev.on = False

else:print('Device {} is not connected. Skipping...'.format(dev.name))

print('All done!')

# Event handlersdef _on_new_device(govee_cli, dev, raw_data):

""" New device event """

connected_str = _get_connected_str(dev.connected)print('NEW DEVICE [{}][{} {}] {} -> Connected: {}'.format(dev.identifier, dev.sku,

→˓ dev.friendly_name, dev.name, \connected_str))

def _on_device_update(govee_cli, dev, old_dev, raw_data):""" Device update event """

connected_str = _get_connected_str(dev.connected)on_str = 'No'if dev.on:

on_str = 'Yes'

if isinstance(dev, device.GoveeRgbLight):color_str = 'Non-RGB'if dev.color:

color_str = dev.color.hex_lelif dev.color_temperature and dev.color_temperature > 0:

color_str = '{} Kelvin'.format(dev.color_temperature)print('DEVICE UPDATE [{}][{} {}] {} -> Connected: {}, On: {}, Brightness: {},

→˓Color: {}'.format(dev.identifier, \dev.sku, dev.friendly_name, dev.name, connected_str, on_str, dev.

→˓brightness, color_str))else:

print('DEVICE UPDATE [{}][{} {}] {} -> Connected: {}, On: {}, Brightness: {}'.→˓format(dev.identifier, dev.sku, \

dev.friendly_name, dev.name, connected_str, on_str, dev.brightness))

# Helperdef _get_connected_str(connected):

""" Get connection status string """

connected_str = 'No'if connected:

connected_str = 'Yes'(continues on next page)

7

Page 12: Govee API Documentation

Govee API Documentation, Release 2.0.0

(continued from previous page)

elif connected is None:connected_str = '???'

return connected_str

if __name__ == '__main__':main()

8 Chapter 3. Usage

Page 13: Govee API Documentation

CHAPTER 4

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

4.1 Types of Contributions

4.1.1 Report Bugs

Report bugs at https://github.com/thomasreiser/govee_api/issues.

If you are reporting a bug, please include:

• Your operating system name and version.

• Any details about your local setup that might be helpful in troubleshooting.

• Detailed steps to reproduce the bug.

4.1.2 Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wantsto implement it.

4.1.3 Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open towhoever wants to implement it.

9

Page 14: Govee API Documentation

Govee API Documentation, Release 2.0.0

4.1.4 Write Documentation

Govee API could always use more documentation, whether as part of the official Govee API docs, in docstrings, oreven on the web in blog posts, articles, and such.

4.1.5 Submit Feedback

The best way to send feedback is to file an issue at https://github.com/thomasreiser/govee_api/issues.

If you are proposing a feature:

• Explain in detail how it would work.

• Keep the scope as narrow as possible, to make it easier to implement.

• Remember that this is a volunteer-driven project, and that contributions are welcome :)

4.2 Get Started!

Ready to contribute? Here’s how to set up govee_api for local development.

1. Fork the govee_api repo on GitHub.

2. Clone your fork locally:

$ git clone [email protected]:your_name_here/govee_api.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set upyour fork for local development:

$ mkvirtualenv govee_api$ cd govee_api/$ python setup.py develop

4. Create a branch for local development:

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing otherPython versions with tox:

$ flake8 govee_api tests$ python setup.py test or pytest$ tox

To get flake8 and tox, just pip install them into your virtualenv.

6. Commit your changes and push your branch to GitHub:

$ git add .$ git commit -m "Your detailed description of your changes."$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.

10 Chapter 4. Contributing

Page 15: Govee API Documentation

Govee API Documentation, Release 2.0.0

4.3 Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

1. The pull request should include tests.

2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a functionwith a docstring, and add the feature to the list in README.rst.

3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check https://travis-ci.com/thomasreiser/govee_api/pull_requests and make sure that the tests pass for all supported Python versions.

4.4 Tips

To run a subset of tests:

$ python -m unittest tests.test_govee_api

4.5 Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry inHISTORY.rst). Then run:

$ bump2version patch # possible: major / minor / patch$ git push$ git push --tags

Travis will then deploy to PyPI if tests pass.

4.3. Pull Request Guidelines 11

Page 16: Govee API Documentation

Govee API Documentation, Release 2.0.0

12 Chapter 4. Contributing

Page 17: Govee API Documentation

CHAPTER 5

Credits

5.1 Development Lead

• Thomas Reiser <[email protected]>

5.2 Contributors

None yet. Why not be the first?

13

Page 18: Govee API Documentation

Govee API Documentation, Release 2.0.0

14 Chapter 5. Credits

Page 19: Govee API Documentation

CHAPTER 6

History

6.1 2.0.0 (2020-05-24)

• Added basic Bluetooth support. In case of IOT devices, it will fallback to BT when no IOT connection ispossible

6.2 1.3.0 (2020-05-17)

• Fixed AWS IoT dependency (oops..)

6.3 1.2.0 (2020-05-13)

• Fix PyPi deployment (IoT certificates were missing)

6.4 1.1.0 (2020-05-12)

• Change brightness from int (0 - 255) to float (0.0 - 1.0)

• Added logic to fetch device status on startup

• Bugfixes

6.5 1.0.0 (2020-05-08)

• Initial version

15

Page 20: Govee API Documentation

Govee API Documentation, Release 2.0.0

16 Chapter 6. History

Page 21: Govee API Documentation

CHAPTER 7

Indices and tables

• genindex

• modindex

• search

17