enkama / hass-variables

Home Assistant variables component
90 stars 12 forks source link

variable.update_sensor - AttributeError: 'Variable' object has no attribute '_attr_extra_state_attributes' #36

Closed hanley-development closed 1 year ago

hanley-development commented 1 year ago

Trying to use the new variable.update_sensor through automation and through developer. I've tried just using values and a template and they all end in the same error:

service: variable.update_sensor
data:
  value: "{{states('sensor.failed_zwave')}}"
  attributes:
    history_1: "{{states('sensor.failed_zwave')}}"
    history_2: "{{ state_attr('sensor.failed_zwave', 'history_1') }}"
    history_3: "{{ state_attr('sensor.failed_zwave', 'history_2') }}"
    history_4: "{{ state_attr('sensor.failed_zwave', 'history_3') }}"
    history_5: "{{ state_attr('sensor.failed_zwave', 'history_4') }}"
    history_6: "{{ state_attr('sensor.failed_zwave', 'history_5') }}"
    history_7: "{{ state_attr('sensor.failed_zwave', 'history_6') }}"
    history_8: "{{ state_attr('sensor.failed_zwave', 'history_7') }}"
    history_9: "{{ state_attr('sensor.failed_zwave', 'history_8') }}"
    history_10: "{{ state_attr('sensor.failed_zwave', 'history_9') }}"
  replace_attributes: false
target:
  entity_id: sensor.zwave_failures

Logger: homeassistant.helpers.script.websocket_api_script Source: custom_components/variable/sensor.py:177 Integration: Variables+History (documentation, issues) First occurred: 5:47:59 PM (2 occurrences) Last logged: 5:57:02 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'Variable' object has no attribute '_attr_extra_state_attributes' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 795, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call await result File "/config/custom_components/variable/sensor.py", line 177, in async_update_variable if not replace_attributes and self._attr_extra_state_attributes is not None: AttributeError: 'Variable' object has no attribute '_attr_extra_state_attributes'

Snuffy2 commented 1 year ago

PR #38 should fix this. Feel free to test the branch if you'd like to and are so inclined before it is released.