Skip to content

Update some deprecated code - #360

Open
Alexious-sh wants to merge 4 commits into
dmamontov:mainfrom
Alexious-sh:fix/deprecated-2025.1
Open

Update some deprecated code#360
Alexious-sh wants to merge 4 commits into
dmamontov:mainfrom
Alexious-sh:fix/deprecated-2025.1

Conversation

@Alexious-sh

@Alexious-sh Alexious-sh commented Jan 4, 2025

Copy link
Copy Markdown

There are several slight refactorings to get rid of errors and warnings, caused by deprecated HA code usage, including:

  • DATA_MEGABYTES, TEMP_CELSIUS constants are removed from the homeassistant.const in favor of UnitOfInformation and UnitOfTemperature subclasses with corresponding fields;
  • SOURCE_TYPE_ROUTER is no longer available in the homeassistant.components.device_tracker. There is a new SourceType.ROUTER field;
  • homeassistant.helpers.typing.ServiceCallType is deprecated and will be removed soon. Use the homeassistant.core.ServiceCall instead;
  • homeassistant.backports.enum.StrEnum is no longer needed and will be removed soon. enum.StrEnum is now available;
  • Fix the light component, which must report supported color modes now.

Should fix the #359

Summary by Sourcery

Update deprecated Home Assistant constants and types.

Bug Fixes:

  • Fix the light component to report supported color modes.

Enhancements:

  • Replace deprecated homeassistant.const constants with UnitOfInformation and UnitOfTemperature subclasses.
  • Replace homeassistant.components.device_tracker.SOURCE_TYPE_ROUTER with SourceType.ROUTER.
  • Replace homeassistant.helpers.typing.ServiceCallType with homeassistant.core.ServiceCall.
  • Remove homeassistant.backports.enum.StrEnum since enum.StrEnum is now available.

Oleksii Shavykin added 4 commits January 4, 2025 15:02
Signed-off-by: Oleksii Shavykin <oshavykin@smarttech.com>
Signed-off-by: Oleksii Shavykin <oshavykin@smarttech.com>
Signed-off-by: Oleksii Shavykin <oshavykin@smarttech.com>
This change fixes the warning light.miwifi_* (<class 'custom_components.miwifi.light.MiWifiLight'>)
does not set supported color modes, this will stop working in Home Assistant Core 2025.3

Signed-off-by: Oleksii Shavykin <oshavykin@smarttech.com>
@sourcery-ai

sourcery-ai Bot commented Jan 4, 2025

Copy link
Copy Markdown

Reviewer's Guide by Sourcery

This PR updates deprecated code from Home Assistant core and some libraries. It also fixes the light component to report supported color modes.

Class diagram showing updated type changes

classDiagram
    class MiWifiServiceCall {
      +get_updater(service: ServiceCall) LuciUpdater
      +async_call_service(service: ServiceCall)* void
    }
    class MiWifiCalcPasswdServiceCall {
      +salt_old: str
      +salt_new: str
      +async_call_service(service: ServiceCall) void
    }
    class MiWifiRequestServiceCall {
      +async_call_service(service: ServiceCall) void
    }
    class MiWifiLight {
      -_attr_is_on: bool
      -_attr_color_mode: ColorMode
      -_attr_supported_color_modes: Set~ColorMode~
      +_handle_coordinator_update() void
    }

    MiWifiServiceCall <|-- MiWifiCalcPasswdServiceCall
    MiWifiServiceCall <|-- MiWifiRequestServiceCall

    note for MiWifiServiceCall "Updated to use ServiceCall instead of ServiceCallType"
    note for MiWifiLight "Added color mode support"
Loading

State diagram for updated constants and enums

stateDiagram-v2
    [*] --> Constants
    Constants --> UnitOfInformation: DATA_MEGABYTES replaced
    Constants --> UnitOfTemperature: TEMP_CELSIUS replaced
    Constants --> SourceType: SOURCE_TYPE_ROUTER replaced

    state Constants {
      UnitOfInformation: MEGABYTES
      UnitOfTemperature: CELSIUS
      SourceType: ROUTER
    }

    note right of Constants
      Updated deprecated constants
      to use new enum classes
    end note
Loading

File-Level Changes

Change Details Files
Replace deprecated constants DATA_MEGABYTES and TEMP_CELSIUS with UnitOfInformation.MEGABYTES and UnitOfTemperature.CELSIUS respectively.
  • Use UnitOfInformation.MEGABYTES instead of DATA_MEGABYTES for memory sensor.
  • Use UnitOfTemperature.CELSIUS instead of TEMP_CELSIUS for temperature sensor.
custom_components/miwifi/sensor.py
Replace deprecated SOURCE_TYPE_ROUTER with SourceType.ROUTER.
  • Use SourceType.ROUTER instead of SOURCE_TYPE_ROUTER.
custom_components/miwifi/device_tracker.py
Replace deprecated homeassistant.helpers.typing.ServiceCallType with homeassistant.core.ServiceCall.
  • Use ServiceCall instead of ServiceCallType in methods and type hints.
custom_components/miwifi/services.py
Remove deprecated homeassistant.backports.enum.StrEnum import and use enum.StrEnum directly.
  • Remove import of homeassistant.backports.enum.StrEnum.
  • Use enum.StrEnum directly.
custom_components/miwifi/enum.py
Fix the light component to report supported color modes.
  • Set color_mode attribute to ColorMode.ONOFF.
  • Set supported_color_modes attribute to {ColorMode.ONOFF}.
custom_components/miwifi/light.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @Alexious-sh - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@smhc

smhc commented Mar 3, 2025

Copy link
Copy Markdown

@dmamontov Any chance of getting this merged? The plugin is currently broken in later versions of HA without these changes.

@ipmerlin

ipmerlin commented Mar 25, 2025

Copy link
Copy Markdown

https://dzen.ru/a/Z6nGKuT6lhYnWdor
Replace files

@coteyka1209

Copy link
Copy Markdown

+1, please merge this, plugin is not working right now

@JuanManuelRomeroGarcia

Copy link
Copy Markdown

Check #422 and Update integration

@JuanManuelRomeroGarcia

Copy link
Copy Markdown

+1, please merge this, plugin is not working right now

Check #422

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.

5 participants