def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self,
                         'etekcity-adapter',
                         'etekcity-adapter',
                         verbose=verbose)

        self.manager = None

        database = Database(self.package_name)
        if database.open():
            config = database.load_config()

            if 'username' in config and len(config['username']) > 0 and \
                    'password' in config and len(config['password']) > 0:
                self.manager = VeSync(config['username'], config['password'])
                self.manager.login()

            database.close()

        self.pairing = False
        self.start_pairing(_TIMEOUT)
Beispiel #2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the VeSync switch platform."""
    from pyvesync.vesync import VeSync

    switches = []

    manager = VeSync(config.get(CONF_USERNAME), config.get(CONF_PASSWORD))

    if not manager.login():
        _LOGGER.error("Unable to login to VeSync")
        return

    manager.update()

    if manager.devices is not None and manager.devices:
        if len(manager.devices) == 1:
            count_string = 'switch'
        else:
            count_string = 'switches'

        _LOGGER.info("Discovered %d VeSync %s",
                     len(manager.devices), count_string)

        for switch in manager.devices:
            switches.append(VeSyncSwitchHA(switch))
            _LOGGER.info("Added a VeSync switch named '%s'",
                         switch.device_name)
    else:
        _LOGGER.info("No VeSync devices found")

    add_devices(switches)
Beispiel #3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the VeSync switch platform."""
    from pyvesync.vesync import VeSync

    switches = []

    manager = VeSync(config.get(CONF_USERNAME), config.get(CONF_PASSWORD))

    if not manager.login():
        _LOGGER.error("Unable to login to VeSync")
        return

    manager.update()

    if manager.devices is not None and manager.devices:
        if len(manager.devices) == 1:
            count_string = 'switch'
        else:
            count_string = 'switches'

        _LOGGER.info("Discovered %d VeSync %s",
                     len(manager.devices), count_string)

        for switch in manager.devices:
            switches.append(VeSyncSwitchHA(switch))
            _LOGGER.info("Added a VeSync switch named '%s'",
                         switch.device_name)
    else:
        _LOGGER.info("No VeSync devices found")

    add_entities(switches)
Beispiel #4
0
    def test_bad_login(self, api_mock, email, password, testid):

        full_return = ({'code': 455}, 200)
        self.mock_api.return_value = full_return
        vesync_obj = VeSync(email, password)
        assert vesync_obj.login() is False
        if testid == 'correct':
            jd = helpers.req_body(vesync_obj, 'login')
            self.mock_api.assert_called_with('/cloud/v1/user/login',
                                             'post',
                                             json=jd)
        else:
            assert not self.mock_api.called
Beispiel #5
0
def test_login(mock_api, email, password, testid):
    return_tuple = {'code': 455, 'msg': 'sdasd'}
    mock_api.return_value.ok = True
    mock_api.return_value.json.return_value = return_tuple
    vesync_obj = VeSync(email, password)
    vesync_login = vesync_obj.login()
    assert vesync_login is False
    if testid == 'correct':
        jd = helpers.req_body(vesync_obj, 'login')
        mock_api.assert_called_with(
            'https://smartapi.vesync.com/cloud/v1/user/login',
            headers=None,
            json=jd,
            timeout=5)
    else:
        assert not mock_api.called
Beispiel #6
0
 def test_good_login(self, api_mock):
     full_return = ({
         'code': 0,
         'result': {
             'accountID': 'sam_actid',
             'token': 'sam_token'
         }
     }, 200)
     self.mock_api.return_value = full_return
     vesync_obj = VeSync('*****@*****.**', 'pass')
     assert vesync_obj.login() is True
     jd = helpers.req_body(vesync_obj, 'login')
     self.mock_api.assert_called_with('/cloud/v1/user/login',
                                      'post',
                                      json=jd)
     assert vesync_obj.token == 'sam_token'
     assert vesync_obj.account_id == 'sam_actid'
Beispiel #7
0
def test_vesync_init(email, password, timezone, testid):
    """Testing only input validation"""
    v_inst = VeSync(email, password, timezone)
    assert isinstance(v_inst, VeSync)
    assert v_inst.username == email
    assert v_inst.password == password

    if testid == 'full correct':
        assert v_inst.time_zone == timezone
    elif testid in ('invalid tz', 'none tz', 'non tz pass', 'empty tz'):
        assert v_inst.time_zone == pyvesync.helpers.DEFAULT_TZ
Beispiel #8
0
def setup(hass, config):
    """Set up the VeSync component."""
    from pyvesync.vesync import VeSync

    conf = config[DOMAIN]

    manager = VeSync(conf.get(CONF_USERNAME), conf.get(CONF_PASSWORD),
                     time_zone=conf.get(CONF_TIME_ZONE))

    if not manager.login():
        _LOGGER.error("Unable to login to VeSync")
        return

    manager.update()

    hass.data[DOMAIN] = {
        'manager': manager
    }

    discovery.load_platform(hass, 'switch', DOMAIN, {}, config)

    return True
class EtekcityAdapter(Adapter):
    """Adapter for Etekcity smart home devices."""
    def __init__(self, verbose=False):
        """
        Initialize the object.

        verbose -- whether or not to enable verbose logging
        """
        self.name = self.__class__.__name__
        Adapter.__init__(self,
                         'etekcity-adapter',
                         'etekcity-adapter',
                         verbose=verbose)

        self.manager = None

        database = Database(self.package_name)
        if database.open():
            config = database.load_config()

            if 'username' in config and len(config['username']) > 0 and \
                    'password' in config and len(config['password']) > 0:
                self.manager = VeSync(config['username'], config['password'])
                self.manager.login()

            database.close()

        self.pairing = False
        self.start_pairing(_TIMEOUT)

    def start_pairing(self, timeout):
        """
        Start the pairing process.

        timeout -- Timeout in seconds at which to quit pairing
        """
        if self.manager is None or self.pairing:
            return

        self.pairing = True

        self.manager.update()

        for dev in self.manager.bulbs:
            _id = 'etekcity-' + dev.uuid
            if _id not in self.devices:
                device = EtekcityBulb(self, _id, dev)
                self.handle_device_added(device)

        for dev in self.manager.outlets:
            _id = 'etekcity-' + dev.uuid
            if _id not in self.devices:
                device = EtekcityOutlet(self, _id, dev)
                self.handle_device_added(device)

        for dev in self.manager.switches:
            _id = 'etekcity-' + dev.uuid
            if _id not in self.devices:
                device = EtekcitySwitch(self, _id, dev)
                self.handle_device_added(device)

        self.pairing = False

    def cancel_pairing(self):
        """Cancel the pairing process."""
        self.pairing = False
Beispiel #10
0
"""Etekcity VeSync integration.""" 
import logging import voluptuous as vol from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_TIME_ZONE) from homeassistant.helpers import config_validation as cv from homeassistant.helpers import discovery _LOGGER = logging.getLogger(__name__) DOMAIN = 'vesync' CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_TIME_ZONE): cv.string, }), }, extra=vol.ALLOW_EXTRA) def setup(hass, config): """Set up the VeSync component.""" from pyvesync.vesync import VeSync conf = config[DOMAIN] manager = VeSync(conf.get(CONF_USERNAME), conf.get(CONF_PASSWORD), time_zone=conf.get(CONF_TIME_ZONE)) if not manager.login(): _LOGGER.error("Unable to login to VeSync") return manager.update() hass.data[DOMAIN] = { 'manager': manager } discovery.load_platform(hass, 'switch', DOMAIN, {}, config) return True
Beispiel #11
0
from pyvesync.vesync import VeSync

a = VeSync('*****@*****.**', 'Microsoft1!1')

a.login()

a.update()
#!/usr/bin/python
from pyvesync.vesync import VeSync
import json

Outlets = []

manager = VeSync("USER_EMAIL", "PASSWORD")
manager.login()
manager.update()

# Get electricity metrics of devices
#print manager.devices[0].device_name
for switch in manager.devices:
    #print("Switch %s is currently using %s watts" % (switch.device_name, switch.get_power()))
    #print("It has used %skWh of electricity today" % (switch.get_kwh_today()))
    #print(switch.device_status)
    #print(switch.device_type)
    #device = Outlet()
    #device.DeviceName = switch.device_name
    #Outlets.append(device)
    x = {
        "name": "VeSync",
        "DeviceName": switch.device_name,
        "State": switch.device_status,
        "CurrentPower": switch.get_power(),
        "Type": switch.device_type,
        "TodayPower": switch.get_kwh_today(),
        "ConnectionStatus": switch.connection_status,
        "DeviceStatus": switch.device_status
    }
    Outlets.append(x)