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

Enhance schedule handling and cooling #511

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Enhance schedule handling and cooling #511

merged 1 commit into from
Sep 17, 2024

Conversation

cgtobi
Copy link
Collaborator

@cgtobi cgtobi commented Sep 17, 2024

Summary by Sourcery

Enhance the schedule handling and cooling features by introducing new properties and methods for managing boiler status, setpoint modes, and HVAC actions. Implement a new ScheduleType enum and improve schedule selection logic. Refactor code for better readability and update pre-commit configuration.

New Features:

  • Introduce a new property to handle boiler valve comfort boost in the module class.
  • Add new properties to the room class to manage boiler status, setpoint mode, setpoint temperature, and HVAC action.
  • Implement a new ScheduleType enum to represent different types of schedules, including therm, cooling, electricity, and event.
  • Add a method to the home class to retrieve available schedules based on the temperature control mode.

Enhancements:

  • Enhance the schedule handling by introducing a mapping for schedule types and updating the logic to select and retrieve schedules based on the temperature control mode.
  • Refactor the async_set_switch method to use boolean literals directly instead of constants.
  • Improve the handling of datetime objects by removing unnecessary noqa comments related to timezone handling.

Build:

  • Update the pre-commit configuration to use a newer version of the ruff-pre-commit hook.

Tests:

  • Modify the test template to remove unnecessary comments and streamline the update measures function call.

@cgtobi cgtobi requested a review from jabesq as a code owner September 17, 2024 22:05
Copy link

sourcery-ai bot commented Sep 17, 2024

Reviewer's Guide by Sourcery

This pull request enhances schedule handling and cooling functionality in the pyatmo library. It introduces new properties and methods for better management of schedules, improves type hinting, and removes unnecessary comments. The changes also include updates to constants, error handling, and minor refactoring across multiple files.

File-Level Changes

Change Details Files
Enhanced schedule handling with new ScheduleType enum and related properties
  • Added ScheduleType enum to represent different schedule types
  • Updated Schedule class with new attributes like type, default, and cooling_away_temp
  • Implemented get_available_schedules method in Home class
  • Modified get_selected_schedule method to consider temperature control mode
src/pyatmo/schedule.py
src/pyatmo/home.py
Improved cooling functionality and HVAC action determination
  • Added new properties to Room class: boiler_status, setpoint_mode, setpoint_temperature, and hvac_action
  • Implemented logic to determine HVAC action based on various conditions
  • Added new constants for HEATING, COOLING, and IDLE states
src/pyatmo/room.py
src/pyatmo/const.py
Refactored and improved type hinting across multiple files
  • Removed unnecessary type comments and noqa statements
  • Updated function signatures with proper type hints
  • Simplified boolean parameter defaults
src/pyatmo/modules/module.py
src/pyatmo/account.py
src/pyatmo/auth.py
src/pyatmo/modules/base_class.py
src/pyatmo/helpers.py
src/pyatmo/modules/device_types.py
src/pyatmo/modules/netatmo.py
Updated constants and removed redundant definitions
  • Added new constants for schedule types and HVAC states
  • Removed redundant ON and OFF constants
  • Reorganized and grouped related constants
src/pyatmo/const.py
Minor improvements and updates
  • Updated ruff-pre-commit hook version
  • Modified test fixture to use 'cooling' type for a schedule
  • Removed unnecessary comments in testing_main_template.py
.pre-commit-config.yaml
fixtures/homesdata.json
tests/testing_main_template.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 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 to tell me if it was helpful.

Comment on lines 236 to 279
@property
def boiler_status(self) -> bool | None:
"""Return the boiler status."""

for module in self.modules.values():
if hasattr(module, "boiler_status"):
if (boiler_status := module.boiler_status) is not None:
return boiler_status

return None

@property
def setpoint_mode(self) -> str:
"""Return the current setpoint mode."""

return self.therm_setpoint_mode or self.cooling_setpoint_mode or UNKNOWN

@property
def setpoint_temperature(self) -> float | None:
"""Return the current setpoint temperature."""

return (
self.therm_setpoint_temperature or self.cooling_setpoint_temperature or None
)

@property
def hvac_action(self) -> str:
"""Return the current HVAC action."""

if self.setpoint_mode == OFF:
return OFF

if self.climate_type != DeviceType.NRV and self.boiler_status is not None:
return HEATING if self.boiler_status else IDLE

if self.boiler_status is True:
return HEATING

if self.heating_power_request is not None and self.heating_power_request > 0:
return HEATING

if self.heating_power_request:
return HEATING
if self.cooling_setpoint_temperature:
return COOLING

return IDLE
Copy link

Choose a reason for hiding this comment

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

suggestion: Add docstrings to new HVAC-related methods

Please add docstrings to the new methods (boiler_status, setpoint_mode, setpoint_temperature, hvac_action) explaining their purpose, return values, and any important logic they contain. This will greatly improve the code's readability and maintainability.

    @property
    def boiler_status(self) -> bool | None:
        """
        Return the boiler status.

        Iterates through modules to find and return the first non-None boiler status.
        Returns None if no boiler status is found.
        """

    @property
    def setpoint_mode(self) -> str:
        """
        Return the current setpoint mode.

        Prioritizes therm_setpoint_mode, then cooling_setpoint_mode.
        Returns UNKNOWN if neither is set.
        """

    @property
    def setpoint_temperature(self) -> float | None:
        """
        Return the current setpoint temperature.

        Prioritizes therm_setpoint_temperature, then cooling_setpoint_temperature.
        Returns None if neither is set.
        """

    @property
    def hvac_action(self) -> str:
        """
        Return the current HVAC action.

        Determines action based on setpoint mode, boiler status, and power requests.
        Returns OFF, HEATING, COOLING, or IDLE based on current state.
        """

for schedule in self.schedules.values()
if self.temperature_control_mode
and schedule.type == SCHEDULE_TYPE_MAPPING[self.temperature_control_mode]
]
Copy link

Choose a reason for hiding this comment

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

suggestion: Add inline comments to explain complex schedule handling logic

The logic in get_selected_schedule and get_available_schedules is quite dense. Consider adding some inline comments to explain the reasoning behind the conditions in the list comprehensions. This will make the code easier to understand and maintain.

@@ -27,7 +27,7 @@ async def main():

await account.async_update_status(home_id=home_id)

strt = 1709766000 + 10 * 60 # 1709421000+15*60
strt = 1709766000 + 10 * 60
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider using datetime objects for improved readability and maintainability

Instead of using raw timestamps, consider using datetime objects and timedelta for better readability and easier maintenance. For example: strt = datetime(2024, 3, 6, 12, 10).timestamp()

from datetime import datetime, timedelta

strt = (datetime(2024, 3, 6, 12, 0) + timedelta(minutes=10)).timestamp()

@@ -27,7 +27,7 @@ async def main():

await account.async_update_status(home_id=home_id)

strt = 1709766000 + 10 * 60 # 1709421000+15*60
strt = 1709766000 + 10 * 60
end = 1709852400 + 10 * 60
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Use consistent naming conventions for variables

Consider renaming 'strt' to 'start' for consistency with the 'end' variable and to improve code readability.

if self.cooling_setpoint_temperature:
return COOLING

return IDLE
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

Suggested change
if self.cooling_setpoint_temperature:
return COOLING
return IDLE
return COOLING if self.cooling_setpoint_temperature else IDLE

@cgtobi cgtobi force-pushed the cooling branch 2 times, most recently from d1f1ad0 to edf70b5 Compare September 17, 2024 22:23
@cgtobi cgtobi merged commit 6c3992e into development Sep 17, 2024
7 checks passed
@cgtobi cgtobi deleted the cooling branch September 17, 2024 22:30
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.

1 participant