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

Clean up raised library exceptions #1558

Merged
merged 1 commit into from Oct 24, 2022
Merged

Conversation

rytilahti
Copy link
Owner

Breaking change: all custom DeviceException derived classes are removed in favor of standard python exceptions and pure DeviceException instances.

This commit removes all unnecessary custom classes in favor of using standard python exceptions or DeviceExceptions:

  • Invalid input values are now reported using TypeErrors and ValueErrors
  • New UnsupportedFeatureException gets now raised if the device does not support the wanted feature

Most downstream users are hopefully catching DeviceExceptions for error handling so this change requires no further action.

The full list of removed exception classes:

  • AirConditionerMiotException
  • AirConditioningCompanionException
  • AirConditioningCompanionException
  • AirDehumidifierException
  • AirQualityMonitorException
  • AirQualityMonitorMiotException
  • CameraException
  • ChuangmiIrException
  • CookerException
  • FanException
  • HeaterException
  • HeaterMiotException
  • HuizuoException
  • AirDogException
  • AirFreshException
  • AirFreshException
  • AirPurifierException
  • FanLeshowException
  • AirHumidifierJsqsException
  • AirHumidifierException
  • AirHumidifierException
  • AirHumidifierException
  • AirHumidifierMiotException
  • AirPurifierMiotException
  • CeilException
  • PhilipsBulbException
  • PhilipsEyecareException
  • PhilipsMoonlightException
  • PhilipsRwreadException
  • YeelightException
  • VacuumException
  • ViomiVacuumException
  • PowerStripException
  • WalkingpadException
  • WifiRepeaterException
  • YeelightDualControlModuleException

This commit removes all unnecessary custom classes in favor of using standard python exceptions or DeviceExceptions:
* Invalid input values are now reported using TypeErrors and ValueErrors
* UnsupportedFeatureException gets raised if the device does not support the wanted feature

Most of of the downstream users are hopefully catching DeviceExceptions for error handling so this change requires no further action.
@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2022

Codecov Report

Merging #1558 (81b3384) into master (8270db5) will decrease coverage by 0.10%.
The diff coverage is 85.00%.

@@            Coverage Diff             @@
##           master    #1558      +/-   ##
==========================================
- Coverage   81.05%   80.94%   -0.11%     
==========================================
  Files         154      154              
  Lines       15073    14987      -86     
  Branches     3697     3661      -36     
==========================================
- Hits        12217    12131      -86     
  Misses       2609     2609              
  Partials      247      247              
Impacted Files Coverage Δ
miio/airconditioningcompanionMCN.py 84.14% <ø> (-0.56%) ⬇️
miio/airqualitymonitor.py 83.76% <0.00%> (-0.41%) ⬇️
miio/aqaracamera.py 64.77% <0.00%> (-0.66%) ⬇️
miio/click_common.py 52.68% <0.00%> (ø)
miio/cooker.py 57.91% <0.00%> (-0.40%) ⬇️
miio/fan_common.py 100.00% <ø> (ø)
miio/gateway/gateway.py 44.16% <0.00%> (-0.29%) ⬇️
...io/integrations/vacuum/dreame/dreamevacuum_miot.py 74.53% <0.00%> (-0.08%) ⬇️
miio/integrations/vacuum/viomi/viomivacuum.py 58.06% <0.00%> (-0.12%) ⬇️
miio/wifirepeater.py 95.65% <ø> (-0.27%) ⬇️
... and 62 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rytilahti rytilahti merged commit 63c2736 into master Oct 24, 2022
@rytilahti rytilahti deleted the janitor/clean_exceptions branch October 24, 2022 01:40
@shbatm
Copy link

shbatm commented Dec 27, 2022

@rytilahti Was trying to test the master branch in Home Assistant and traced an error back to this PR:

 Setup failed for xiaomi_miio: Unable to import component: cannot import name 'GatewayException' from 'miio.gateway.gateway' (/usr/local/lib/python3.10/site-packages/src/python-miio/miio/gateway/gateway.py) 

Obviously I know this hasn't been released yet, but since I didn't see GatewayException listed in the removed classes above, I wanted to make sure this gets flagged for updating the HA Core side when it gets there.

@rytilahti
Copy link
Owner Author

rytilahti commented Jan 1, 2023

@shbatm Thanks for the reminder, I'm aware of the issue. The current master has diverged much from the one used by homeassistant to make the library more robust and easier to extend (related to #1495). This will necessitate a major refactoring of the integration which will also get rid of the direct imports inside homeassistant codebase to make it more maintainable, so this should be a non-issue in the future.

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.

None yet

3 participants