Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def async_setup(hass, config):
"""Set up the WyzeApi parent component."""
_LOGGER.debug("""
-------------------------------------------------------------------
Wyze Bulb and Switch Home Assistant Integration
Version: v0.5.0
This is a custom integration
If you have any issues with this you need to open an issue here:
https://github.com/JoshuaMulliken/ha-wyzeapi/issues
-------------------------------------------------------------------""")
_LOGGER.debug("""Creating new WyzeApi component""")
wyzeapi_account = WyzeApi(config[DOMAIN].get(CONF_USERNAME),
config[DOMAIN].get(CONF_PASSWORD))
await wyzeapi_account.async_init()
sensor_support = config[DOMAIN].get(CONF_SENSORS)
light_support = config[DOMAIN].get(CONF_LIGHT)
switch_support = config[DOMAIN].get(CONF_SWITCH)
lock_support = config[DOMAIN].get(CONF_LOCK)
if not wyzeapi_account.is_valid_login():
_LOGGER.error("Not connected to Wyze account. Unable to add devices. Check your configuration.")
return False
_LOGGER.debug("Connected to Wyze account")
wyzeapi_devices = await wyzeapi_account.async_get_devices()
# Store the logged in account object for the platforms to use.
hass.data[DOMAIN] = {
"wyzeapi_account": wyzeapi_account
except InvalidConsumerSecret:
return self.async_abort(reason="client_secret")
except InvalidCredentials:
return await self._show_authenticaticate_form({"base": "credentials"})
except AgreementsRetrievalError:
return self.async_abort(reason="no_agreements")
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected error while authenticating")
return self.async_abort(reason="unknown_auth_fail")
self.displays = displays
self.username = user_input[CONF_USERNAME]
self.password = user_input[CONF_PASSWORD]
self.tenant = user_input[CONF_TENANT]
return await self.async_step_display()
CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments"
CONF_MODEL = "model"
MODEL_YI = "yi"
MODEL_XIAOFANG = "xiaofang"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_HOST): cv.template,
vol.Required(CONF_MODEL): vol.Any(MODEL_YI, MODEL_XIAOFANG),
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_PATH, default=DEFAULT_PATH): cv.string,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_FFMPEG_ARGUMENTS, default=DEFAULT_ARGUMENTS): cv.string,
}
)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up a Xiaomi Camera."""
_LOGGER.debug("Received configuration for model %s", config[CONF_MODEL])
async_add_entities([XiaomiCamera(hass, config)])
class XiaomiCamera(Camera):
"""Define an implementation of a Xiaomi Camera."""
def __init__(self, hass, config):
"""Initialize."""
DEFAULT_HOST = '127.0.0.1'
DEFAULT_USER = 'user'
DEFAULT_PASS = 'pass'
DEFAULT_NAME = 'TV Ambilights'
BASE_URL = 'https://{0}:1926/6/{1}' # for older philps tv's, try changing this to 'http://{0}:1925/1/{1}'
DEFAULT_HUE = 360
DEFAULT_SATURATION = 0
DEFAULT_BRIGHTNESS = 255
TIMEOUT = 5.0
CONNFAILCOUNT = 5
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string,
vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
})
# these are the names of the effects, change the names in the quotes to change the name displayed on the front-end
EFFECT_MANUAL = "Manual"
EFFECT_STANDARD = "Standard"
EFFECT_NATURAL = "Natural"
EFFECT_IMMERSIVE = "Football"
EFFECT_VIVID = "Vivid"
EFFECT_GAME = "Game"
EFFECT_COMFORT = "Comfort"
EFFECT_RELAX = "Relax"
EFFECT_ADAP_BRIGHTNESS = "Lumina"
EFFECT_ADAP_COLOR = "Colora"
EFFECT_RETRO = "Retro"
EFFECT_SPECTRUM = "Spectrum"
_LOGGER = logging.getLogger(__name__)
_THROTTLED_REFRESH = None
DEFAULT_NAME = 'Deluge'
DEFAULT_PORT = 58846
DHT_UPLOAD = 1000
DHT_DOWNLOAD = 1000
SENSOR_TYPES = {
'current_status': ['Status', None],
'download_speed': ['Down Speed', 'kB/s'],
'upload_speed': ['Up Speed', 'kB/s'],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Required(CONF_USERNAME): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_MONITORED_VARIABLES, default=[]): vol.All(
cv.ensure_list, [vol.In(SENSOR_TYPES)]),
})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Deluge sensors."""
from deluge_client import DelugeRPCClient
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
def setup(hass, config):
"""Set up the Zabbix component."""
from pyzabbix import ZabbixAPI, ZabbixAPIException
conf = config[DOMAIN]
if conf[CONF_SSL]:
schema = 'https'
else:
schema = 'http'
url = urljoin('{}://{}'.format(schema, conf[CONF_HOST]), conf[CONF_PATH])
username = conf.get(CONF_USERNAME, None)
password = conf.get(CONF_PASSWORD, None)
zapi = ZabbixAPI(url)
try:
zapi.login(username, password)
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
except ZabbixAPIException as login_exception:
_LOGGER.error("Unable to login to the Zabbix API: %s", login_exception)
return False
hass.data[DOMAIN] = zapi
return True
DEFAULT_GAS = True
CONF_SOLAR = 'solar'
DEFAULT_SOLAR = False
CONF_TENANT = 'tenant'
DEFAULT_TENANT = 'eneco'
CONF_NAME = 'display_name'
DEFAULT_NAME = ''
# Validation of the user's configuration
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_KEY): cv.string,
vol.Required(CONF_SECRET): cv.string,
vol.Optional(CONF_GAS, default=DEFAULT_GAS): cv.boolean,
vol.Optional(CONF_SOLAR, default=DEFAULT_SOLAR): cv.boolean,
vol.Optional(CONF_TENANT, default=DEFAULT_TENANT): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
"""Setup toon."""
from toonapilib.toonapilibexceptions import (InvalidConsumerSecret,
InvalidConsumerKey,
InvalidCredentials)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the NZBGet sensors."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
ssl = 's' if config.get(CONF_SSL) else ''
name = config.get(CONF_NAME)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
monitored_types = config.get(CONF_MONITORED_VARIABLES)
url = "http{}://{}:{}/jsonrpc".format(ssl, host, port)
try:
nzbgetapi = NZBGetAPI(
api_url=url, username=username, password=password)
nzbgetapi.update()
except (requests.exceptions.ConnectionError,
requests.exceptions.HTTPError) as conn_err:
_LOGGER.error("Error setting up NZBGet API: %s", conn_err)
return False
devices = []
for ng_type in monitored_types:
new_sensor = NZBGetSensor(
from homeassistant.helpers.event import async_track_time_interval
_LOGGER = logging.getLogger(__name__)
DOMAIN = "namecheapdns"
INTERVAL = timedelta(minutes=5)
UPDATE_URL = "https://dynamicdns.park-your-domain.com/update"
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_DOMAIN): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_HOST, default="@"): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass, config):
"""Initialize the namecheap DNS component."""
host = config[DOMAIN][CONF_HOST]
domain = config[DOMAIN][CONF_DOMAIN]
password = config[DOMAIN][CONF_PASSWORD]
session = async_get_clientsession(hass)
DEFAULT_PORT = 25
DEFAULT_TIMEOUT = 5
DEFAULT_DEBUG = False
DEFAULT_STARTTLS = False
DEFAULT_PRODUCT_NAME = 'HomeAssistant'
# pylint: disable=no-value-for-parameter
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_RECIPIENT): vol.Email(),
vol.Optional(CONF_SERVER, default=DEFAULT_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
vol.Optional(CONF_SENDER): vol.Email(),
vol.Optional(CONF_STARTTLS, default=DEFAULT_STARTTLS): cv.boolean,
vol.Optional(CONF_USERNAME): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
vol.Optional(CONF_DEBUG, default=DEFAULT_DEBUG): cv.boolean,
})
def get_service(hass, config, discovery_info=None):
"""Get the mail notification service."""
mail_service = MailNotificationService(
config.get(CONF_SERVER),
config.get(CONF_PORT),
config.get(CONF_TIMEOUT),
config.get(CONF_SENDER),
config.get(CONF_STARTTLS),
config.get(CONF_USERNAME),
config.get(CONF_PASSWORD),
config.get(CONF_RECIPIENT),
config.get(CONF_PRODUCT_NAME, DEFAULT_PRODUCT_NAME),