Ejemplo n.º 1
0
    def test_canTriggerActionWheneverConditionIsMet(self, ast, smart_home):
        light_bulb = Appliance(ApplianceTypes.LIGHT, "bulbazoro")
        light_bulb2 = Appliance(ApplianceTypes.LIGHT, "cxarmandero")
        smart_home.addAppliance(light_bulb)
        smart_home.addAppliance(light_bulb2)
        smart_home, value = ast.parse(
            "asignu brilo de bulbazoro pli unu al brilo de bulbazoro "
            "cxiufoje la koloro de cxarmandero estas egala al rugxo").evaluate(
                smart_home)

        self.fastForwardBy(smart_home, seconds=2)
        assert smart_home.variables["bulbazoro"].properties[
            ApplianceProperties.BRIGHTNESS.value] == 1
        smart_home.variables["cxarmandero"].properties[
            ApplianceProperties.COLOR.value] = Color.RED.value
        self.fastForwardBy(smart_home, seconds=2)
        assert smart_home.variables["bulbazoro"].properties[
            ApplianceProperties.BRIGHTNESS.value] == 2
        smart_home.variables["cxarmandero"].properties[
            ApplianceProperties.COLOR.value] = Color.BLUE.value
        self.fastForwardBy(smart_home, seconds=2)
        smart_home.variables["cxarmandero"].properties[
            ApplianceProperties.COLOR.value] = Color.RED.value
        self.fastForwardBy(smart_home, seconds=2)
        assert smart_home.variables["bulbazoro"].properties[
            ApplianceProperties.BRIGHTNESS.value] == 3
Ejemplo n.º 2
0
    def test_canUseRepeatedActionToPropagateLampColor(self, ast, smart_home):
        light_bulbs = []
        for i in range(100):
            light_bulb = Appliance(ApplianceTypes.LIGHT, f"{i + 1:03d}")
            light_bulb.properties[
                ApplianceProperties.COLOR.value] = Color.WHITE.value
            smart_home.addAppliance(light_bulb)
            light_bulbs += [light_bulb]
        smart_home.variables["ampoloj"] = light_bulbs
        smart_home.variables["indekso"] = 1
        smart_home, value = ast.parse("""
            dum indekso estas pli malgranda ol cent tiam
                asignu indekso pli unu al io 
                poste asignu la koloro de indeksa de ampoloj 
                    al la koloro de ia de ampoloj
                poste asignu io al indekso
            finu cxiu sekundo""").evaluate(smart_home)
        for bulb in smart_home.variables["ampoloj"]:
            assert bulb.properties[
                ApplianceProperties.COLOR.value] == Color.WHITE.value

        smart_home.variables["ampoloj"][0].properties[
            ApplianceProperties.COLOR.value] = Color.RED.value
        self.fastForwardBy(smart_home, seconds=1)
        for bulb in smart_home.variables["ampoloj"]:
            print(bulb.name)
            assert bulb.properties[
                ApplianceProperties.COLOR.value] == Color.RED.value
Ejemplo n.º 3
0
def create_boiler(name, row=0, col=0):
    boiler = Appliance(ApplianceTypes.BOILER, name)
    smart_home.addAppliance(boiler)
    app.addLabel(name, row=row, column=col)
    app.addMeter(name, row, col)

    def update_gui():
        desired_temperature = boiler.properties[
            ApplianceProperties.DESIRED_TEMPERATURE.value]
        current_temperature = boiler.properties[
            ApplianceProperties.CURRENT_TEMPERATURE.value]
        if boiler.isTurnedOn():
            current_temperature += (desired_temperature -
                                    current_temperature) / 20
            is_on_character = "☺"
        else:
            current_temperature -= current_temperature / 20
            is_on_character = "☻"
        boiler.properties[ApplianceProperties.CURRENT_TEMPERATURE.
                          value] = current_temperature
        app.setMeter(name, current_temperature,
                     " " + is_on_character + " " + name)

    app.registerEvent(update_gui)
    return boiler
Ejemplo n.º 4
0
    def test_delayedActionsSaveAClosureOfTheirDictationState(
            self, ast, smart_home):
        light_bulb = Appliance(ApplianceTypes.LIGHT, "bulbazoro")
        smart_home.variables["hundo"] = 2
        smart_home.addAppliance(light_bulb)
        smart_home, value = ast.parse(
            "asignu hundo al brilo de bulbazoro je unu sekundo").evaluate(
                smart_home)
        smart_home.variables["hundo"] = 10

        self.fastForwardBy(smart_home, seconds=2)
        assert smart_home.variables["bulbazoro"].properties[
            ApplianceProperties.BRIGHTNESS.value] == 2
Ejemplo n.º 5
0
def create_efficient_bulb(name, row=0, col=0):
    bulb = Appliance(ApplianceTypes.LIGHT, name)
    smart_home.addAppliance(bulb)
    app.addLabel(name, row=row, column=col)
    bulb_wrapper = GuiBulb(bulb)

    def update_gui():
        if bulb_wrapper.has_changed():
            app.setLabelBg(*bulb_wrapper.get_gui_settings())
            bulb_wrapper.refresh()

    app.registerEvent(update_gui)
    return bulb
Ejemplo n.º 6
0
def create_door(name, row=0, col=0):
    door = Appliance(ApplianceTypes.SWITCH, name)
    smart_home.addAppliance(door)
    app.addLabel(name, row=row, column=col)

    def update_gui():
        if door.isTurnedOn():
            is_on_character = "□"
        else:
            is_on_character = "■"
        app.setLabel(name, is_on_character + " " + name)

    app.registerEvent(update_gui)
    return door
Ejemplo n.º 7
0
def create_speaker(name, row=0, col=0):
    speaker = Appliance(ApplianceTypes.SWITCH, name)
    smart_home.addAppliance(speaker)
    app.addLabel(name, row=row, column=col)

    def update_gui():
        if speaker.isTurnedOn():
            is_on_character = "♫♪"
        else:
            is_on_character = "  "
        app.setLabel(name, name + is_on_character)

    app.registerEvent(update_gui)
    return speaker