tolwi / hassio-ecoflow-cloud

EcoFlow Cloud Integration for Home Assistant
353 stars 60 forks source link

Timestamp exception with Delta Max. Diagnostic shows "ValueError: year 55480 is out of range" #72

Closed semeif closed 1 year ago

semeif commented 1 year ago

When I add a Delta Max (2000) to Hass (german locale, Timezone Europe/Berlin) The Device is added but the values are not updating. When I try to change any settings i get the following error (Error from Diagnostic and Diagnostic information @below):

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/ecoflow_cloud/sensor.py:158 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 12:37:46 (1 occurrences) Last logged: 12:37:46

[3728950288] 'timestamp' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1910, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1950, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 226, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 811, in entity_service_call future.result() # pop exception if have ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1034, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 851, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1088, in async_turn_on await self.hass.async_add_executor_job(ft.partial(self.turn_on, *kwargs)) File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ecoflow_cloud/switch.py", line 32, in turn_on self.send_set_message(1, self.command_dict(1)) File "/config/custom_components/ecoflow_cloud/entities/init.py", line 47, in send_set_message super().send_set_message({self._mqtt_key: target_value}, command) File "/config/custom_components/ecoflow_cloud/entities/init.py", line 26, in send_set_message self._client.send_set_message(target_dict, command) File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 272, in send_set_message self.data.update_to_target_state(mqtt_state) File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 143, in update_to_target_state self.broadcast() File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 156, in broadcast self.params_observable.on_next(self.params) File "/usr/local/lib/python3.11/site-packages/reactivex/subject/subject.py", line 59, in on_next super().on_next(value) File "/usr/local/lib/python3.11/site-packages/reactivex/observer/observer.py", line 39, in on_next self._on_next_core(value) File "/usr/local/lib/python3.11/site-packages/reactivex/subject/subject.py", line 66, in _on_next_core observer.on_next(value) File "/usr/local/lib/python3.11/site-packages/reactivex/observer/autodetachobserver.py", line 28, in on_next self._on_next(value) File "/config/custom_components/ecoflow_cloud/sensor.py", line 158, in params_update self._attrs[ATTR_STATUS_DATA_LAST_UPDATE] = datetime.fromtimestamp(data['timestamp'], UTC)


KeyError: 'timestamp'

**When I add the device as Diagnostic I get the following Information:**

Diagnostic Error information:
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: root
Source: custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py:147
Integration: EcoFlow-Cloud (documentation, issues)
First occurred: 12:29:05 (2 occurrences)
Last logged: 12:30:05

Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 244, in on_message
    self.data.update_data(raw)
  File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 147, in update_data
    self.__params_time = datetime.fromtimestamp(raw['timestamp'], UTC)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: year 55480 is out of range

**Diagnostic Information:**
{
  "home_assistant": {
    "installation_type": "Home Assistant Container",
    "version": "2023.6.1",
    "dev": false,
    "hassio": false,
    "virtualenv": false,
    "python_version": "3.11.3",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Berlin",
    "os_name": "Linux",
    "os_version": "6.1.21-v8+",
    "run_as_root": true
  },
  "custom_components": {
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "ecoflow_cloud": {
      "version": "0.10.0",
      "requirements": [
        "paho-mqtt==1.6.1",
        "reactivex==4.0.4"
      ]
    }
  },
  "integration_manifest": {
    "domain": "ecoflow_cloud",
    "name": "Ecoflow-Cloud",
    "codeowners": [
      "@tolwi"
    ],
    "config_flow": true,
    "documentation": "https://github.com/tolwi/hassio-ecoflow-cloud",
    "iot_class": "cloud_push",
    "issue_tracker": "https://github.com/tolwi/hassio-ecoflow-cloud/issues",
    "requirements": [
      "paho-mqtt==1.6.1",
      "reactivex==4.0.4"
    ],
    "version": "0.10.0",
    "is_built_in": false
  },
  "data": {
    "params": {},
    "set": [],
    "set_reply": [],
    "get": [],
    "get_reply": [],
    "raw_data": [
      {
        "params": {
          "bmsMaster.f32ShowSoc": 79.44581,
          "bmsMaster.designCap": 40000,
          "bmsMaster.remainCap": 29846,
          "bmsMaster.temp": 28,
          "bmsMaster.bmsFault": 0,
          "bmsMaster.maxCellTemp": 28,
          "bmsMaster.vol": 57021,
          "bmsMaster.soh": 100,
          "bmsMaster.sysVer": 16843784,
          "bmsMaster.bqSysStatReg": 128,
          "bmsMaster.amp": 6228,
          "bmsMaster.outputWatts": 0,
          "bmsMaster.soc": 79,
          "bmsMaster.num": 0,
          "bmsMaster.openBmsIdx": 1,
          "bmsMaster.type": 1,
          "bmsMaster.minCellTemp": 28,
          "bmsMaster.errCode": 0,
          "latestTimeStamp": 1688639345399,
          "bmsMaster.maxMosTemp": 31,
          "bmsMaster.tagChgAmp": 20000,
          "bmsMaster.maxCellVol": 4060,
          "bmsMaster.inputWatts": 0,
          "bmsMaster.minMosTemp": 31,
          "bmsMaster.remainTime": 0,
          "bmsMaster.minCellVol": 4053,
          "bmsMaster.fullCap": 37568,
          "bmsMaster.cellId": 1,
          "bmsMaster.cycles": 1
        },
        "version": "1.0",
        "cmdId": 0,
        "cmdFunc": 0,
        "id": 1493818360731145648,
        "addr": 0,
        "timestamp": 1688639345399
      }
    ]
  }
}
semeif commented 1 year ago

Found this one: https://bobbyhadz.com/blog/python-valueerror-year-is-out-of-range#:~:text=The%20Python%20%22ValueError%3A%20year%20is%20out%20of%20range%22,timestamp%20by%201000%20if%20it%20is%20in%20milliseconds.