Exemplo n.º 1
0
def index():
    state = ACState(Config.context)  # ステータスデータを読み込む

    # 日本語変換
    jstate = state.convertToJapanese()

    return render_template('index.html', state=state, jstate=jstate)
Exemplo n.º 2
0
def modeTemperature(temperatureMode):
    # ACStateインスタンス読み込み
    state = ACState(Config.context)

    # ステート変更 ログファイル追加
    if temperatureMode == "up" and state.temperature >= 30:
        flash('最大設定温度です')
    elif temperatureMode == "up":
        state.temperature += 1

    if temperatureMode == "down" and state.temperature <= 18:
        flash('最低設定温度です')
    elif temperatureMode == "down":
        state.temperature -= 1

    # stateを元に赤外線送信
    if not state.sendSignalToAC():
        flash('信号を送信できませんでした')

    # 日本語変換
    jstate = state.convertToJapanese()

    # 実験用ログ書き込み
    lffe = LogFileForExperiment(context=Config.context,
                                acstate=state,
                                ipaddr=request.remote_addr)
    lffe.write_log_file()

    return render_template('index.html', state=state, jstate=jstate)
    def setUp(self):
        with open(Config.test_context["acStateCSVFilePath"], "w") as f:
            f.write("2016-04-01 13:24:00,off,cool,25,breeze")

        with open(Config.test_context["acStateLogCSVFilePath"], "w") as f:
            f.write("2016-04-01 13:24:00,off,cool,25,breeze")

        self.acstate = ACState(Config.test_context)
Exemplo n.º 4
0
def modeOperating(operatingMode):
    # ACStateインスタンス読み込み
    state = ACState(Config.context)

    # ステート変更 ログファイル追加
    state.operating = operatingMode

    # stateを元に赤外線送信
    if not state.sendSignalToAC():
        flash('信号を送信できませんでした')

    # 日本語変換
    jstate = state.convertToJapanese()

    # 実験用ログ書き込み
    lffe = LogFileForExperiment(context=Config.context,
                                acstate=state,
                                ipaddr=request.remote_addr)
    lffe.write_log_file()

    return render_template('index.html', state=state, jstate=jstate)
class ACStateTest(unittest.TestCase):
    def setUp(self):
        with open(Config.test_context["acStateCSVFilePath"], "w") as f:
            f.write("2016-04-01 13:24:00,off,cool,25,breeze")

        with open(Config.test_context["acStateLogCSVFilePath"], "w") as f:
            f.write("2016-04-01 13:24:00,off,cool,25,breeze")

        self.acstate = ACState(Config.test_context)

    def tearDown(self):
        os.remove(Config.test_context["acStateCSVFilePath"])
        os.remove(Config.test_context["acStateLogCSVFilePath"])

    def test_initiate_and_getter(self):
        # test ACState initiation
        self.assertEqual(self.acstate.__repr__(),
                         '<2016-04-01 13:24:00 off cool 25 breeze>')

    def test_makeSignalName(self):
        signal = self.acstate._makeSignalName()
        self.assertEqual(signal, 'off')

        self.acstate.onoff = "on"
        signal = self.acstate._makeSignalName()
        self.assertEqual(signal, 'cool25breeze')

    def test_states_setter_restrict(self):
        self.acstate.onoff = "on"
        self.assertEqual(self.acstate.onoff, 'on')

        # setter制限が働いているか確認
        self.acstate.onoff = "ok"
        self.assertEqual(self.acstate.onoff, 'on')

        self.acstate.operating = "warm"
        self.assertEqual(self.acstate.operating, 'warm')

        # setter制限が働いているか確認
        self.acstate.operating = "supercool"
        self.assertEqual(self.acstate.operating, 'warm')

        self.acstate.temperature = 30
        self.assertEqual(self.acstate.temperature, 30)

        # setter制限が働いているか確認
        self.acstate.temperature += 1
        self.assertEqual(self.acstate.temperature, 30)

        self.acstate.temperature = 18
        self.assertEqual(self.acstate.temperature, 18)

        # setter制限が働いているか確認
        self.acstate.temperature -= 1
        self.assertEqual(self.acstate.temperature, 18)

        self.acstate.wind = "strong"
        self.assertEqual(self.acstate.wind, "strong")

        # setter制限が働いているか確認
        self.acstate.wind = "week"
        self.assertEqual(self.acstate.wind, "strong")