Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the config attribute to the sensor #28

Closed
alanmilinovic opened this issue Mar 26, 2024 · 6 comments
Closed

Return the config attribute to the sensor #28

alanmilinovic opened this issue Mar 26, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@alanmilinovic
Copy link

alanmilinovic commented Mar 26, 2024

Traceback (most recent call last):
  File "/config/custom_components/python_script/sensor.py", line 65, in update
    exec(self.code)
  File "<string>", line 3, in <module>
AttributeError: 'PythonSensor' object has no attribute 'config'
@alanmilinovic
Copy link
Author

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
Copy link
Author

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
Copy link
Author

alanmilinovic commented Mar 26, 2024

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.

@AlexxIT AlexxIT added the enhancement New feature or request label Mar 26, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Mar 26, 2024

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

@alanmilinovic
Copy link
Author

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

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

@AlexxIT AlexxIT self-assigned this Mar 27, 2024
@AlexxIT AlexxIT changed the title Stopped working after last update Return the config attribute to the sensor Dec 7, 2024
@AlexxIT AlexxIT added this to the v1.0.3 milestone Dec 7, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Dec 7, 2024

https://github.com/AlexxIT/PythonScriptsPro/releases/tag/v1.0.3

@AlexxIT AlexxIT closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants