Skip to content

Fix: Type error for interval_minutes#305

Merged
MaStr merged 2 commits intomainfrom
fix-type-errors
Mar 17, 2026
Merged

Fix: Type error for interval_minutes#305
MaStr merged 2 commits intomainfrom
fix-type-errors

Conversation

@MaStr
Copy link
Owner

@MaStr MaStr commented Mar 17, 2026

Closed #302

@MaStr MaStr added this to the 0.7.1 milestone Mar 17, 2026
@MaStr MaStr self-assigned this Mar 17, 2026
Copilot AI review requested due to automatic review settings March 17, 2026 15:01
@MaStr MaStr added the bug Something isn't working label Mar 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a runtime TypeError in the default battery control logic by ensuring the logic factory passes an integer time resolution (minutes) into DefaultLogic, avoiding string/int arithmetic issues when configuration values come in as strings (e.g., via Home Assistant).

Changes:

  • Update logic factory API to accept an explicit time_resolution_minutes argument and pass it to DefaultLogic.
  • Update core loop to call the logic factory with self.time_resolution instead of reading time_resolution_minutes directly inside the factory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/batcontrol/logic/logic.py Adjusts create_logic to take time_resolution_minutes explicitly and use it for DefaultLogic(interval_minutes=...).
src/batcontrol/core.py Passes the validated/normalized self.time_resolution into the logic factory during each run.

print_class_message = True
@staticmethod
def create_logic(config: dict, timezone) -> LogicInterface:
def create_logic(time_resolution_minutes: int,config: dict, timezone) -> LogicInterface:
Comment on lines +500 to +502
this_logic_run = LogicFactory.create_logic(self.time_resolution,
self.config,
self.timezone)
@MaStr
Copy link
Owner Author

MaStr commented Mar 17, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Mar 17, 2026

@MaStr I've opened a new pull request, #306, to work on those changes. Once the pull request is ready, I'll request review from you.

…_minutes (#306)

* Initial plan

* Fix PEP8 spacing in logic.py and add string time_resolution tests

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a runtime TypeError caused by interval_minutes being treated as a string in the control logic, by ensuring the logic factory receives the already-coerced integer time resolution from Batcontrol.

Changes:

  • Update logic factory API to take time_resolution_minutes explicitly and pass it through to DefaultLogic.
  • Update Batcontrol.run() to call the logic factory with self.time_resolution (int).
  • Add tests covering string time_resolution_minutes handling and basic logic factory behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/batcontrol/logic/logic.py Changes Logic.create_logic signature and uses the passed resolution for DefaultLogic(interval_minutes=...).
src/batcontrol/core.py Passes self.time_resolution into LogicFactory.create_logic(...) during run().
tests/batcontrol/test_core.py Adds regression tests for string time_resolution_minutes coercion and logic factory instantiation.

Comment on lines +13 to 22
def create_logic(time_resolution_minutes: int, config: dict, timezone) -> LogicInterface:
""" Select and configure a logic class based on the given configuration """
request_type = config.get('type', 'default').lower()
interval_minutes = config.get('time_resolution_minutes', 60)
logic = None
if request_type == 'default':
if Logic.print_class_message:
logger.info('Using default logic')
Logic.print_class_message = False
logic = DefaultLogic(timezone, interval_minutes=interval_minutes)
logic = DefaultLogic(timezone, interval_minutes=time_resolution_minutes)
if config.get('battery_control_expert', None) is not None:
Comment on lines +500 to +502
this_logic_run = LogicFactory.create_logic(self.time_resolution,
self.config,
self.timezone)
Comment on lines +347 to +356
@pytest.mark.parametrize('resolution_str', ['60', '15'])
def test_logic_factory_accepts_string_resolution_as_int(self, resolution_str):
"""Logic factory must produce a valid logic instance when given an int resolution"""
logic = LogicFactory.create_logic(
int(resolution_str),
{'type': 'default'},
datetime.timezone.utc
)
assert logic is not None
assert logic.interval_minutes == int(resolution_str)
@MaStr MaStr merged commit b834082 into main Mar 17, 2026
17 checks passed
@MaStr MaStr deleted the fix-type-errors branch March 17, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typerror of int and str at BatControl Logic

3 participants