-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
63 lines (40 loc) · 1.58 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from http import HTTPStatus
import requests
import logging
import asyncio
import aiohttp
import async_timeout
import json
import base64
import subprocess
from typing import Any
import voluptuous as vol
import homeassistant.loader as loader
import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries
from homeassistant.helpers import discovery
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema({DOMAIN: {}}, extra=vol.ALLOW_EXTRA)
def subp_run(cmd, allow_failure: bool = False) -> subprocess.CompletedProcess:
output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if not allow_failure and output.returncode != 0:
_LOGGER.error(f'[{DOMAIN}]The command "{cmd}" failed.')
return output
async def async_setup(hass, config):
if DOMAIN not in config:
return True
return True
async def async_setup_entry(hass, config_entry):
"""Set up this integration using UI."""
if hass.data.get(DOMAIN) is not None:
return False
if config_entry.source == config_entries.SOURCE_IMPORT:
hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
return False
async def map(service):
_LOGGER.error(f'[{DOMAIN}] Map Change Service call!')
cmd = 'bash -c "$(wget -O - \'https://raw.githubusercontent.com/miumida/HA_Related/main/changing_map.sh\')"'
_LOGGER.error(subp_run(cmd).stdout)
hass.services.async_register(DOMAIN, "map_change", map)
return True