Skip to content

Modernize the code for newer Home Assistant versions, fix strict physics validation warnings, and improve error visibility#119

Open
ma27in wants to merge 2 commits into
djansen1987:mainfrom
ma27in:bugfix/fix-sensor-types
Open

Modernize the code for newer Home Assistant versions, fix strict physics validation warnings, and improve error visibility#119
ma27in wants to merge 2 commits into
djansen1987:mainfrom
ma27in:bugfix/fix-sensor-types

Conversation

@ma27in
Copy link
Copy Markdown

@ma27in ma27in commented Apr 1, 2026

Home Assistant Architecture Updates:

  1. Swapped state for native_value: Renamed the state property to native_value in the SAJeSolarMeterSensor class. Modern Home Assistant Core strictly requires this for sensors so it can handle unit conversions and state classes under the hood.
  2. Modernized Timestamp Generation: Replaced the deprecated Python datetime.utcnow() math with Home Assistant's built-in dt.utcnow().timestamp() * 1000. This prevents the integration from crashing in Python 3.12+.

Device Class Corrections (Physics Fixes)

  1. Changed ENERGY to POWER: Updated the device_class for several sensors (nowPower, peakPower, systemPower, totalLoadPower, and solarLoadPower). Home Assistant was likely throwing warnings because these sensors measure in Watts (Power), but were incorrectly labeled as measuring Energy (which expects kWh).

Better Error Logging

  1. Exposed Hidden Errors: Fixed a bug in the try/except block where network errors were failing silently. The code now properly catches aiohttp.ClientError and asyncio.TimeoutError as the variable err and actively prints the actual error message to the Home Assistant logs.

Code Cleanup

  1. Removed Unused Imports: Deleted the imports for async_timeout and async_get_clientsession at the top of the file since they were no longer being used by the integration. This keeps the code clean and prevents potential container load errors.

Removed unnecessary imports
Replaced legacy epochmilliseconds with standard way of doing this in HA
Fixed exception logs
Renamed state to native_value
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.

2 participants