PythonScriptsPro icon indicating copy to clipboard operation
PythonScriptsPro copied to clipboard

Stopped working after last update

Open alanmilinovic opened this issue 1 year ago • 5 comments

Traceback (most recent call last): File "/config/custom_components/python_script/sensor.py", line 65, in update exec(self.code) File "", line 3, in AttributeError: 'PythonSensor' object has no attribute 'config'

alanmilinovic avatar Mar 26 '24 06:03 alanmilinovic

This is how my ssh_command.py looks like.

from paramiko import SSHClient, AutoAddPolicy

host = self.config.get("host")
port = self.config.get("port")
username = self.config.get("user")
password = self.config.get("pass")
command = self.config.get("cmd")

client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(host, port, username, password)
stdin, stdout, stderr = client.exec_command(command)
resp = stdout.read()
stderr.read()
client.close()

self.state = f"\n{ resp.decode()[:250] }"
self._attr_extra_state_attributes = { "response": resp.decode() }

So far all worked well, not sure what changed in last update, tried to revert to previous version and same error.

alanmilinovic avatar Mar 26 '24 06:03 alanmilinovic

This is my sensor.

  - platform: python_script
    name: 1NUC Model
    unique_id: "1nuc_model"
    icon: mdi:desktop-tower
    scan_interval: 63072000 #2 Years in seconds
    file: scripts/remote_ssh_command.py
    host: !secret 1nuc_host
    port: !secret 1nuc_port
    user: "user"
    pass: !secret password
    cmd: >
      sudo dmidecode -s system-product-name

alanmilinovic avatar Mar 26 '24 07:03 alanmilinovic

I found the issue is in "self.config.get" function. The question is what has changed and how to get attribute value defined in sensor? Tried with data attribute, but it doesn't work, I guess data is only working when called as a service.

alanmilinovic avatar Mar 26 '24 13:03 alanmilinovic

Config removed from first release (two months ago). I can return it, no problem. In next version when I'll have time. Or you can make PR https://github.com/AlexxIT/PythonScriptsPro/blob/edd9032670dd960ac54ff1dbd21b64dbe4cd8ef4/custom_components/python_script/sensor.py#L31

AlexxIT avatar Mar 26 '24 15:03 AlexxIT

Config removed from first release (two months ago). I can return it, no problem. In next version when I'll have time. Or you can make PR

https://github.com/AlexxIT/PythonScriptsPro/blob/edd9032670dd960ac54ff1dbd21b64dbe4cd8ef4/custom_components/python_script/sensor.py#L31

Great, I manually return it and will wait for you to apply PR. Thanks

alanmilinovic avatar Mar 26 '24 19:03 alanmilinovic