Esempio n. 1
0
def update_group(group_id, group_list):
    logger = logging.getLogger(__name__)
    lifx = LifxLAN()
    db = Session()
    group = db.query(Group_d).filter_by(id=group_id).first()

    is_new = group.id not in group_list
    is_updated = group.devices_updated

    if is_new or is_updated:
        status = []
        if is_new:
            status.append("New")

        if is_updated:
            status.append("Updated")

        new_group = None
        try:
            new_group = GroupExt(
                lifx.get_devices_by_name(
                    [device.name for device in group.devices]
                ).get_device_list()
            )
        except WorkflowException:
            logger.warning(
                "Group failed - WorkflowException",
                exc_info=True
            )

        if new_group is not None:
            status_str = ",".join(status)
            devices_str = ", ".join(
                [device.name for device in group.devices]
            )

            logger.info(
                "{} - Group: {}\nDevices: {}"
                .format(status_str, group.name, devices_str)
            )

            group_list[group.id] = new_group
            group.devices_updated = False
            if len(group.devices) != len(new_group.get_device_list()):
                # just using this as a flag to force it to try again
                group.devices_updated = True

            db.commit()
    db.close()
Esempio n. 2
0
class ReturnConnectedLightsViaName:
    def __init__(self, device_list: list) -> list:
        """
        -- MUST UTILISE WITH --
        returns a list of connection objects - i.e. requested lifx bulb(s)

        Args:
            device_list (list): Names of bulb(s)

        Returns:
            list: list of connection objects
        """
        self.device_list = device_list

    def __enter__(self):
        self.connection = LifxLAN(len(self.device_list))
        return self.connection.get_devices_by_name(self.device_list)

    def __exit__(self, exc_type, exc_val, exc_tb):
        del self.connection
Esempio n. 3
0
        officeOne.set_power("on", duration=5000)
        sleep(1)
        print("Two on!")
        officeTwo.set_power("on", duration=4000)
        sleep(1)
        print("Three on!")
        officeThree.set_power("on", duration=3000)
        sleep(1)
    except:
        print("Exception ocurred.")


lifx = LifxLAN(7)
officeLightGroup = lifx.get_devices_by_group("Office")
officeLights = officeLightGroup.get_device_list()
officeOne = lifx.get_devices_by_name("Office One")
officeTwo = lifx.get_devices_by_name("Office Two")
officeThree = lifx.get_devices_by_name("Office Three")

if len(officeLights) < 3:
    print(f"Did not discover all office lights! ({len(officeLights)} of 3)")
    devices = lifx.get_lights()
    print("\nFound {} light(s):\n".format(len(devices)))
    for d in devices:
        try:
            print(d)
        except:
            pass
    sys.exit(-1)