Esempio n. 1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the panasonic cloud components."""
    import pcomfortcloud

    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)

    api = pcomfortcloud.Session(username, password, verifySsl=False)
    api.login()
    # Get panasonic Devices from api.
    _LOGGER.debug("Add panasonic devices")
    add_devices([PanasonicDevice(device, api) for device in api.get_devices()],
                True)
Esempio n. 2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    import pcomfortcloud
    from pcomfortcloud import constants
    """Set up the panasonic cloud components."""
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)

    api = pcomfortcloud.Session(username, password, verifySsl=False)
    api.login()

    _LOGGER.debug("Adding panasonic devices")

    devices = []
    for device in api.get_devices():
        _LOGGER.debug("Setting up %s ...", device)
        devices.append(PanasonicDevice(device, api, constants))

    add_entities(devices, True)
Esempio n. 3
0
    async def _create_device(self, username, password):
        """Create device."""
        import pcomfortcloud
        try:

            api = pcomfortcloud.Session(username, password, verifySsl=False)
            devices = await self.hass.async_add_executor_job(api.get_devices)
            if not devices:
                return self.async_abort(reason="No devices")
        except asyncio.TimeoutError:
            return self.async_abort(reason="device_timeout")
        except ClientError:
            _LOGGER.exception("ClientError")
            return self.async_abort(reason="device_fail")
        except Exception:  # pylint: disable=broad-except
            _LOGGER.exception("Unexpected error creating device")
            return self.async_abort(reason="device_fail")

        return await self._create_entry(username, password)
Esempio n. 4
0
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
    """Establish connection with Comfort Cloud."""
    import pcomfortcloud

    conf = entry.data
    if PANASONIC_DEVICES not in hass.data:
        hass.data[PANASONIC_DEVICES] = []

    username = conf[CONF_USERNAME]
    password = conf[CONF_PASSWORD]
    force_outside_sensor = entry.options.get(CONF_FORCE_OUTSIDE_SENSOR,
                                             DEFAULT_FORCE_OUTSIDE_SENSOR)
    if CONF_FORCE_OUTSIDE_SENSOR in conf:
        force_outside_sensor = conf[CONF_FORCE_OUTSIDE_SENSOR]
    enable_daily_energy_sensor = entry.options.get(
        CONF_ENABLE_DAILY_ENERGY_SENSOR, DEFAULT_ENABLE_DAILY_ENERGY_SENSOR)

    api = pcomfortcloud.Session(username, password, verifySsl=False)
    devices = await hass.async_add_executor_job(api.get_devices)
    for device in devices:
        try:
            api_device = PanasonicApiDevice(hass, api, device,
                                            force_outside_sensor,
                                            enable_daily_energy_sensor)
            await api_device.update()
            if enable_daily_energy_sensor:
                await api_device.update_energy()
            hass.data[PANASONIC_DEVICES].append(api_device)
        except Exception as e:
            _LOGGER.warning(f"Failed to setup device: {device['name']} ({e})")

    if hass.data[PANASONIC_DEVICES]:
        for component in COMPONENT_TYPES:
            hass.async_create_task(
                hass.config_entries.async_forward_entry_setup(
                    entry, component))

    return True
def main():
    """ Start pcomfortcloud Comfort Cloud command line """

    parser = argparse.ArgumentParser(
        description='Read or change status of pcomfortcloud Climate devices')

    parser.add_argument('username',
                        help='Username for pcomfortcloud Comfort Cloud')

    parser.add_argument('password',
                        help='Password for pcomfortcloud Comfort Cloud')

    parser.add_argument('-t',
                        '--token',
                        help='File to store token in',
                        default='~/.pcomfortcloud-token')

    parser.add_argument('-s',
                        '--skipVerify',
                        help='Skip Ssl verification if set as True',
                        type=str2bool,
                        nargs='?',
                        const=True,
                        default=False)

    parser.add_argument('-r',
                        '--raw',
                        help='Raw dump of response',
                        type=str2bool,
                        nargs='?',
                        const=True,
                        default=False)

    commandparser = parser.add_subparsers(help='commands', dest='command')

    commandparser.add_parser('list', help="Get a list of all devices")

    get_parser = commandparser.add_parser('get', help="Get status of a device")

    get_parser.add_argument(dest='device', type=int, help='Device number #')

    set_parser = commandparser.add_parser('set', help="Set status of a device")

    set_parser.add_argument(dest='device', type=int, help='Device number #')

    set_parser.add_argument('-p',
                            '--power',
                            choices=[
                                pcomfortcloud.constants.Power.On.name,
                                pcomfortcloud.constants.Power.Off.name
                            ],
                            help='Power mode')

    set_parser.add_argument('-t',
                            '--temperature',
                            type=float,
                            help="Temperature")

    set_parser.add_argument('-f',
                            '--fanSpeed',
                            choices=[
                                pcomfortcloud.constants.FanSpeed.Auto.name,
                                pcomfortcloud.constants.FanSpeed.Low.name,
                                pcomfortcloud.constants.FanSpeed.LowMid.name,
                                pcomfortcloud.constants.FanSpeed.Mid.name,
                                pcomfortcloud.constants.FanSpeed.HighMid.name,
                                pcomfortcloud.constants.FanSpeed.High.name
                            ],
                            help='Fan speed')

    set_parser.add_argument(
        '-m',
        '--mode',
        choices=[
            pcomfortcloud.constants.OperationMode.Auto.name,
            pcomfortcloud.constants.OperationMode.Cool.name,
            pcomfortcloud.constants.OperationMode.Dry.name,
            pcomfortcloud.constants.OperationMode.Heat.name,
            pcomfortcloud.constants.OperationMode.Fan.name
        ],
        help='Operation mode')

    set_parser.add_argument('-e',
                            '--eco',
                            choices=[
                                pcomfortcloud.constants.EcoMode.Auto.name,
                                pcomfortcloud.constants.EcoMode.Quiet.name,
                                pcomfortcloud.constants.EcoMode.Powerful.name
                            ],
                            help='Eco mode')

    # set_parser.add_argument(
    #     '--airswingauto',
    #     choices=[
    #         pcomfortcloud.constants.AirSwingAutoMode.Disabled.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.AirSwingLR.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.AirSwingUD.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.Both.name],
    #     help='Automation of air swing')

    set_parser.add_argument(
        '-y',
        '--airSwingVertical',
        choices=[
            pcomfortcloud.constants.AirSwingUD.Auto.name,
            pcomfortcloud.constants.AirSwingUD.Down.name,
            pcomfortcloud.constants.AirSwingUD.DownMid.name,
            pcomfortcloud.constants.AirSwingUD.Mid.name,
            pcomfortcloud.constants.AirSwingUD.UpMid.name,
            pcomfortcloud.constants.AirSwingUD.Up.name
        ],
        help='Vertical position of the air swing')

    set_parser.add_argument(
        '-x',
        '--airSwingHorizontal',
        choices=[
            pcomfortcloud.constants.AirSwingLR.Auto.name,
            pcomfortcloud.constants.AirSwingLR.Left.name,
            pcomfortcloud.constants.AirSwingLR.LeftMid.name,
            pcomfortcloud.constants.AirSwingLR.Mid.name,
            pcomfortcloud.constants.AirSwingLR.RightMid.name,
            pcomfortcloud.constants.AirSwingLR.Right.name
        ],
        help='Horizontal position of the air swing')

    dump_parser = commandparser.add_parser('dump',
                                           help="Dump data of a device")

    dump_parser.add_argument(dest='device', type=int, help='Device number 1-x')

    history_parser = commandparser.add_parser('history',
                                              help="Dump history of a device")

    history_parser.add_argument(dest='device',
                                type=int,
                                help='Device number 1-x')

    history_parser.add_argument(dest='mode',
                                type=str,
                                help='mode (Day, Week, Month, Year)')

    history_parser.add_argument(dest='date',
                                type=str,
                                help='date of day like 20190807')

    args = parser.parse_args()

    session = pcomfortcloud.Session(args.username, args.password, args.token,
                                    args.raw, args.skipVerify == False)
    session.login()
    try:
        if args.command == 'list':
            print("list of devices and its device id (1-x)")
            for idx, device in enumerate(session.get_devices()):
                if (idx > 0):
                    print('')

                print("device #{}".format(idx + 1))
                print_result(device, 4)

        if args.command == 'get':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]
            print("reading from device '{}' ({})".format(
                device['name'], device['id']))

            print_result(session.get_device(device['id']))

        if args.command == 'set':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]
            print("writing to device '{}' ({})".format(device['name'],
                                                       device['id']))

            kwargs = {}

            if args.power is not None:
                kwargs['power'] = pcomfortcloud.constants.Power[args.power]

            if args.temperature is not None:
                kwargs['temperature'] = args.temperature

            if args.fanSpeed is not None:
                kwargs['fanSpeed'] = pcomfortcloud.constants.FanSpeed[
                    args.fanSpeed]

            if args.mode is not None:
                kwargs['mode'] = pcomfortcloud.constants.OperationMode[
                    args.mode]

            if args.eco is not None:
                kwargs['eco'] = pcomfortcloud.constants.EcoMode[args.eco]

            if args.airSwingHorizontal is not None:
                kwargs[
                    'airSwingHorizontal'] = pcomfortcloud.constants.AirSwingLR[
                        args.airSwingHorizontal]

            if args.airSwingVertical is not None:
                kwargs[
                    'airSwingVertical'] = pcomfortcloud.constants.AirSwingUD[
                        args.airSwingVertical]

            session.set_device(device['id'], **kwargs)

        if args.command == 'dump':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]

            print_result(session.dump(device['id']))

        if args.command == 'history':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]

            print_result(session.history(device['id'], args.mode, args.date))

    except pcomfortcloud.ResponseError as ex:
        print(ex.text)
Esempio n. 6
0
def main():
    """ Start pcomfortcloud Comfort Cloud command line """

    parser = argparse.ArgumentParser(
        description='Read or change status of pcomfortcloud Climate devices')

    parser.add_argument('username',
                        help='Username for pcomfortcloud Comfort Cloud')

    parser.add_argument('password',
                        help='Password for pcomfortcloud Comfort Cloud')

    parser.add_argument(
        '-t',
        '--token',
        metavar='FILE',
        help='File to store session cache in (default: %(default)s)',
        default='~/.pcomfortcloud-token.js')

    parser.add_argument('-s',
                        '--skipVerify',
                        help='Skip Ssl verification if set as True',
                        type=str2bool,
                        nargs='?',
                        const=True,
                        default=False)

    parser.add_argument('-r',
                        '--raw',
                        help='Raw dump of response',
                        action='store_true',
                        default=False)

    parser.add_argument('-v',
                        '--verbose',
                        dest='verbosity',
                        help='Increase verbosity of debug output',
                        action='count',
                        default=0)

    parser.add_argument(
        '-c',
        '--cache',
        help=
        "Cached information is retrieved from the token file to speed up operation, (default: %(default)s)",
        type=pcomfortcloud.constants.Cache,
        choices=list(pcomfortcloud.constants.Cache),
        default=pcomfortcloud.constants.Cache.Token)

    commandparser = parser.add_subparsers(help='commands', dest='command')

    commandparser.add_parser('list', help="Get a list of all devices")

    get_parser = commandparser.add_parser('get', help="Get status of a device")

    get_parser.add_argument(dest='device', type=int, help='Device number #')

    set_parser = commandparser.add_parser('set', help="Set status of a device")

    set_parser.add_argument(dest='device', type=int, help='Device number #')

    set_parser.add_argument('-p',
                            '--power',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.Power),
                            help='Power mode')

    set_parser.add_argument('-t',
                            '--temperature',
                            type=float,
                            help="Temperature")

    set_parser.add_argument('-f',
                            '--fanSpeed',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.FanSpeed),
                            help='Fan speed')

    set_parser.add_argument('-m',
                            '--mode',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.OperationMode),
                            help='Operation mode')

    set_parser.add_argument('-e',
                            '--eco',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.EcoMode),
                            help='Eco mode')

    set_parser.add_argument('-n',
                            '--nanoe',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.NanoeMode),
                            help='Nanoe mode')

    # set_parser.add_argument(
    #     '--airswingauto',
    #     choices=[
    #         pcomfortcloud.constants.AirSwingAutoMode.Disabled.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.AirSwingLR.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.AirSwingUD.name,
    #         pcomfortcloud.constants.AirSwingAutoMode.Both.name],
    #     help='Automation of air swing')

    set_parser.add_argument('-y',
                            '--airSwingVertical',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.AirSwingUD),
                            help='Vertical position of the air swing')

    set_parser.add_argument('-x',
                            '--airSwingHorizontal',
                            choices=namesFromEnum(
                                pcomfortcloud.constants.AirSwingLR),
                            help='Horizontal position of the air swing')

    dump_parser = commandparser.add_parser('dump',
                                           help="Dump data of a device")

    dump_parser.add_argument(dest='device', type=int, help='Device number 1-x')

    history_parser = commandparser.add_parser('history',
                                              help="Dump history of a device")

    history_parser.add_argument(dest='device',
                                type=int,
                                help='Device number 1-x')

    history_parser.add_argument(dest='mode',
                                type=str,
                                help='mode (Day, Week, Month, Year)')

    history_parser.add_argument(dest='date',
                                type=str,
                                help='date of day like 20190807')

    args = parser.parse_args()

    if args.verbosity > 1:
        level = logging.DEBUG
    elif args.verbosity > 0:
        level = logging.INFO
    else:
        level = logging.WARN
    logging.basicConfig(level=level, format='--- [%(levelname)s] %(message)s')

    session = pcomfortcloud.Session(args.username,
                                    args.password,
                                    args.token,
                                    args.raw,
                                    not args.skipVerify,
                                    caching=args.cache)
    session.login()
    try:
        if args.command == 'list':
            print("list of devices and its device id (1-x)")
            for idx, device in enumerate(session.get_devices()):
                if idx > 0:
                    print('')

                print("device #{}".format(idx + 1))
                print_result(device, 4)

        if args.command == 'get':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]
            print("reading from device '{}' ({})".format(
                device['name'], device['id']))

            print_result(session.get_device(device['id']))

        if args.command == 'set':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]
            print("writing to device '{}' ({})".format(device['name'],
                                                       device['id']))

            kwargs = {}

            if args.power is not None:
                kwargs['power'] = pcomfortcloud.constants.Power[args.power]

            if args.temperature is not None:
                kwargs['temperature'] = args.temperature

            if args.fanSpeed is not None:
                kwargs['fanSpeed'] = pcomfortcloud.constants.FanSpeed[
                    args.fanSpeed]

            if args.mode is not None:
                kwargs['mode'] = pcomfortcloud.constants.OperationMode[
                    args.mode]

            if args.eco is not None:
                kwargs['eco'] = pcomfortcloud.constants.EcoMode[args.eco]

            if args.nanoe is not None:
                kwargs['nanoe'] = pcomfortcloud.constants.NanoeMode[args.nanoe]

            if args.airSwingHorizontal is not None:
                kwargs[
                    'airSwingHorizontal'] = pcomfortcloud.constants.AirSwingLR[
                        args.airSwingHorizontal]

            if args.airSwingVertical is not None:
                kwargs[
                    'airSwingVertical'] = pcomfortcloud.constants.AirSwingUD[
                        args.airSwingVertical]

            session.set_device(device['id'], **kwargs)

        if args.command == 'dump':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]

            print_result(session.dump(device['id']))

        if args.command == 'history':
            if int(args.device) <= 0 or int(args.device) > len(
                    session.get_devices()):
                raise Exception(
                    "device not found, acceptable device id is from {} to {}".
                    format(1, len(session.get_devices())))

            device = session.get_devices()[int(args.device) - 1]

            print_result(session.history(device['id'], args.mode, args.date))

    except pcomfortcloud.ResponseError as ex:
        print(ex.text)