Skip to content

Commit c41c8c4

Browse files
Antonio ...claude
andcommitted
fix: Handle None default in state_helper.get_int() (v1.2.1)
## 🐛 Critical Bugfix Fixed TypeError in state_helper.get_int() when default=None is passed. ### Issue ChargerController calls: ```python state_helper.get_int(self.hass, self._charger_current, default=None) ``` Old implementation tried to convert None to float: ```python float(default) # TypeError: float() argument must be a string or a real number, not 'NoneType' ``` ### Fix Updated get_int() to handle None default: - Check if default is None before conversion - Return None if state is unavailable and default is None - Preserve existing behavior for non-None defaults ### Changes - utils/state_helper.py: Updated get_int() with None handling - Updated version to 1.2.1 in const.py, manifest.json, __init__.py ### Testing Test with: - Charger current sensor unavailable on startup - Charger current sensor with valid value - Charger current sensor with invalid value 🚀 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bd0735d commit c41c8c4

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎custom_components/ev_smart_charger/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2323
hass.data.setdefault(DOMAIN, {})
2424

2525
_LOGGER.info("=" * 64)
26-
_LOGGER.info("🚗 EV Smart Charger v1.2.0 - Starting setup")
26+
_LOGGER.info("🚗 EV Smart Charger v1.2.1 - Starting setup")
2727
_LOGGER.info("=" * 64)
2828

2929
# ========== PHASE 1: SETUP PLATFORMS (Helper Entities) ==========
@@ -120,7 +120,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
120120
entry.async_on_unload(entry.add_update_listener(_reload_on_update))
121121

122122
_LOGGER.info("=" * 64)
123-
_LOGGER.info("✅ EV Smart Charger v1.2.0 - Setup completed successfully!")
123+
_LOGGER.info("✅ EV Smart Charger v1.2.1 - Setup completed successfully!")
124124
_LOGGER.info("=" * 64)
125125

126126
return True

‎custom_components/ev_smart_charger/const.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# ========== INTEGRATION METADATA ==========
44
DOMAIN = "ev_smart_charger"
5-
VERSION = "1.2.0"
5+
VERSION = "1.2.1"
66
DEFAULT_NAME = "EV Smart Charger"
77

88
# ========== PLATFORMS ==========

‎custom_components/ev_smart_charger/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "ev_smart_charger",
33
"name": "EV Smart Charger",
4-
"version": "1.2.0",
4+
"version": "1.2.1",
55
"documentation": "https://github.com/antbald/ha-ev-smart-charger",
66
"issue_tracker": "https://github.com/antbald/ha-ev-smart-charger/issues",
77
"codeowners": ["@antbald"],

‎custom_components/ev_smart_charger/utils/state_helper.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@ def get_float(hass: HomeAssistant, entity_id: str, default: float = 0.0) -> floa
4040
return default
4141

4242

43-
def get_int(hass: HomeAssistant, entity_id: str, default: int = 0) -> int:
44-
"""Get entity state as int with error handling."""
43+
def get_int(hass: HomeAssistant, entity_id: str, default: int | None = 0) -> int | None:
44+
"""
45+
Get entity state as int with error handling.
46+
47+
Args:
48+
hass: Home Assistant instance
49+
entity_id: Entity ID to read
50+
default: Default value if read fails (can be None)
51+
52+
Returns:
53+
Int value, default, or None
54+
"""
55+
if default is None:
56+
float_result = get_float(hass, entity_id, 0.0)
57+
# If we got the fallback 0.0, check if state was actually unavailable
58+
state = get_state(hass, entity_id)
59+
if state in [None, "unknown", "unavailable"]:
60+
return None
61+
return int(float_result)
4562
return int(get_float(hass, entity_id, float(default)))
4663

4764

0 commit comments

Comments
 (0)