Skip to content

Commit

Permalink
Merge pull request #7 from glebsterx/master
Browse files Browse the repository at this point in the history
Возможность указать хост по умолчанию в конфигурации
  • Loading branch information
AlexxIT authored Apr 19, 2024
2 parents 601be03 + 346b820 commit 6d1bb37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ If the integration is not in the list, you need to clear the browser cache.

```yaml
ssh_command:
host: 192.168.1.123 # Optional
port: 22 # Optional
username: pi # Optional
password: raspberry # Optional
```
## Usage
Expand All @@ -38,6 +42,7 @@ script:
- service: ssh_command.exec_command
data:
host: 192.168.1.123
port: 22
user: pi
pass: raspberry
command: ls -la
Expand Down
24 changes: 20 additions & 4 deletions custom_components/ssh_command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import logging

import voluptuous as vol

from homeassistant.core import ServiceCall
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD
from homeassistant.helpers import config_validation as cv
from paramiko import AutoAddPolicy, RSAKey, SSHClient

_LOGGER = logging.getLogger(__name__)

DOMAIN = 'ssh_command'

SSH_COMMAND_SCHEMA = vol.All(
vol.Schema({
vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_PORT): cv.string,
vol.Optional(CONF_USERNAME): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
}, extra=vol.PREVENT_EXTRA))

CONFIG_SCHEMA = vol.Schema({
DOMAIN: SSH_COMMAND_SCHEMA
}, extra=vol.ALLOW_EXTRA)

def setup(hass, hass_config):
hass.data[DOMAIN] = hass_config.get(DOMAIN, {})
async def exec_command(call: ServiceCall):
host = call.data.get('host', '172.17.0.1')
port = call.data.get('port', 22)
username = call.data.get('user', 'pi')
password = call.data.get('pass', 'raspberry')
host = call.data.get('host', hass.data[DOMAIN].get(CONF_HOST, '172.17.0.1'))
port = call.data.get('port', hass.data[DOMAIN].get(CONF_PORT, 22))
username = call.data.get('user', hass.data[DOMAIN].get(CONF_USERNAME, 'pi'))
password = call.data.get('pass', hass.data[DOMAIN].get(CONF_PASSWORD, 'raspberry'))
command = call.data.get('command')
ssh_private_key_path = call.data.get('ssh_private_key_path')

Expand Down

0 comments on commit 6d1bb37

Please sign in to comment.