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

Swap octoprint to use an external library #46611

Merged
merged 10 commits into from
Mar 1, 2021

Conversation

rfleming71
Copy link
Contributor

@rfleming71 rfleming71 commented Feb 16, 2021

Proposed change

To prepare to switching octoprint over to config_flow, move the API code out into a library.

I used a client that has wrapper classes around the DTOs, which required a few other changes. If the HA teams prefers the client return json instead, I can update to do that.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@rfleming71 rfleming71 mentioned this pull request Feb 16, 2021
21 tasks
@rfleming71 rfleming71 changed the base branch from dev to rework-octoprint February 16, 2021 16:10
homeassistant/components/octoprint/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/sensor.py Show resolved Hide resolved
tests/components/octoprint/test_binary_sensor.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinHjelmare MartinHjelmare 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!

@frenck?

@rfleming71
Copy link
Contributor Author

The code seems to be failing on import homekit config. Any pointers in hunting down what broke?

@MartinHjelmare
Copy link
Member

Most likely a flaky test unrelated to this PR. I restarted CI.

@frenck frenck assigned frenck and unassigned frenck Feb 18, 2021
@frenck frenck self-requested a review February 18, 2021 18:19
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

A couple of small comments. All-in-all, good job!

homeassistant/components/octoprint/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/octoprint/sensor.py Outdated Show resolved Hide resolved
@frenck frenck self-requested a review February 23, 2021 12:20
@frenck
Copy link
Member

frenck commented Feb 23, 2021

First attempt with an invalid host resulted in:

2021-02-23 13:24:19 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up octoprint platform for sensor
Traceback (most recent call last):
  File "/home/frenck/code/home-assistant/home-assistant/homeassistant/helpers/entity_platform.py", line 200, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/frenck/code/home-assistant/home-assistant/homeassistant/components/octoprint/sensor.py", line 36, in async_setup_platform
    if coordinator.data["printer"]:
TypeError: 'NoneType' object is not subscriptable

A second attempt at my Octoprint dev instance (which has no permanent printer connected):

2021-02-23 13:27:06 ERROR (MainThread) [homeassistant.components.octoprint] Failed to update printer data 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('http://10.10.11.125:80/api/printer')

Third attempt with a printer actively connected worked.

@rfleming71
Copy link
Contributor Author

Both situations should be fixed with more reasonable exception messages into the log file. Updated the data update to only catch the printer offline exception and let anything from the getjob get raised.

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@frenck frenck merged commit 09ea84d into home-assistant:rework-octoprint Mar 1, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants