Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 3, 2025

The number.increment and number.decrement services were failing with a TypeError when used with number entities that return their value property as a string instead of a numeric type.

The Problem

Some integrations (like the dreo integration) return the entity value as a string representation rather than a numeric type. This caused the following error:

TypeError: can only concatenate str (not "float") to str

The error occurred in these lines:

  • increment.py line 39: value = entity.value + amount
  • decrement.py line 39: value = entity.value - amount

The Solution

Convert entity.value to float before performing arithmetic operations:

  • increment.py: value = float(entity.value) + amount
  • decrement.py: value = float(entity.value) - amount

This ensures type compatibility while maintaining backward compatibility with entities that already return numeric types.

Testing

The fix has been validated with:

  • ✅ Ruff linting and formatting
  • ✅ Pylint code quality checks
  • ✅ Backward compatibility with existing numeric values
  • ✅ Support for string representations of numbers
  • ✅ Minimal code changes (1 line per file)

Fixes #985.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…e is string

Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Jun 3, 2025

Copy link

sonarqubecloud bot commented Jun 3, 2025

Please retry analysis of this Pull-Request directly on SonarQube Cloud

@Copilot Copilot AI changed the title [WIP] Unknown error in number.increment Fix TypeError in number increment/decrement services when entity.value is string Jun 3, 2025
@Copilot Copilot AI requested a review from frenck June 3, 2025 08:00
Copilot finished work on behalf of frenck June 3, 2025 08:00
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.

Unknown error in number.increment
2 participants