Skip to content

Commit ae65fb7

Browse files
committed
Update safe_float function to handle None and int types, and comment out unused DC charger register code on inverter
1 parent e67745a commit ae65fb7

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

custom_components/sigen/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,14 @@ def from_entity_description(cls, description,
253253
def safe_float(value: Any, precision: int = 6) -> Optional[float]:
254254
"""Convert to float only if possible, else None."""
255255
try:
256-
return round(float(str(value)), precision)
256+
if value is None:
257+
return 0.0
258+
if isinstance(value, float):
259+
return round(value, precision)
260+
if isinstance(value, int):
261+
return round(float(value), precision)
262+
else:
263+
return round(float(str(value)), precision)
257264
except (InvalidOperation, TypeError, ValueError):
258265
_LOGGER.warning("Could not convert value %s (type %s) to float", value, type(value).__name__)
259266
return None

custom_components/sigen/modbus.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,12 @@ async def async_read_inverter_data(self, inverter_name: str, update_frequency:
827827
**{name: reg for name, reg in INVERTER_PARAMETER_REGISTERS.items()
828828
if reg.register_type != RegisterType.WRITE_ONLY and
829829
reg.update_frequency >= update_frequency },
830-
**{name: reg for name, reg in DC_CHARGER_RUNNING_INFO_REGISTERS.items()
831-
if reg.register_type != RegisterType.WRITE_ONLY and
832-
reg.update_frequency >= update_frequency },
833-
**{name: reg for name, reg in DC_CHARGER_PARAMETER_REGISTERS.items()
834-
if reg.register_type != RegisterType.WRITE_ONLY and
835-
reg.update_frequency >= update_frequency },
830+
# **{name: reg for name, reg in DC_CHARGER_RUNNING_INFO_REGISTERS.items()
831+
# if reg.register_type != RegisterType.WRITE_ONLY and
832+
# reg.update_frequency >= update_frequency },
833+
# **{name: reg for name, reg in DC_CHARGER_PARAMETER_REGISTERS.items()
834+
# if reg.register_type != RegisterType.WRITE_ONLY and
835+
# reg.update_frequency >= update_frequency },
836836
}
837837
_LOGGER.debug("Reading %s Inverter registers. update_frequency is %s",
838838
len(registers_to_read), update_frequency)

0 commit comments

Comments
 (0)