diff --git a/tests/assets/config_full.json b/tests/assets/config_full.json index b545b36..d4284dc 100644 --- a/tests/assets/config_full.json +++ b/tests/assets/config_full.json @@ -25,7 +25,7 @@ "watt": 2000, "beep": true }, - "update_interval": 30, + "update_interval": 15, "beep_volume": 5, "auto_reboot": false, "sync_cache": true diff --git a/tests/test_wmconfig.py b/tests/test_wmconfig.py index 5bc3e34..46f49ed 100644 --- a/tests/test_wmconfig.py +++ b/tests/test_wmconfig.py @@ -143,7 +143,7 @@ def test_load_full(self): self.assertTrue(config.config.wattmeter.warning.beep) self.assertEqual(config.config.wattmeter.caution.watt, 2000) self.assertTrue(config.config.wattmeter.caution.beep) - self.assertEqual(config.config.wattmeter.update_interval, 30) + self.assertEqual(config.config.wattmeter.update_interval, 15) self.assertEqual(config.config.wattmeter.beep_volume, 5) self.assertFalse(config.config.wattmeter.auto_reboot) self.assertTrue(config.config.wattmeter.sync_cache) @@ -178,7 +178,7 @@ def test_load_min(self): self.assertEqual(config.config.wattmeter.max.watt, 3000) self.assertIsNone(config.config.wattmeter.warning) self.assertIsNone(config.config.wattmeter.caution) - self.assertEqual(config.config.wattmeter.update_interval, 15) + self.assertEqual(config.config.wattmeter.update_interval, 30) self.assertEqual(config.config.wattmeter.beep_volume, 3) self.assertTrue(config.config.wattmeter.auto_reboot) self.assertFalse(config.config.wattmeter.sync_cache) diff --git a/wattmeter/meter.py b/wattmeter/meter.py index ff1ca6b..2f3615f 100644 --- a/wattmeter/meter.py +++ b/wattmeter/meter.py @@ -167,10 +167,15 @@ def _updateTime(self): # エラーの記録だけ行いタスクループの停止(例外の送出)はしない self.logging.e(e) - def _prepareClient(self): + def _prepareClient(self, force_scan=False): """ Wi-SUNクライアントの使用準備を行う + Parameters + ---------- + force_scan : bool + SKSCANを強制的に実行する場合はTrue + Raises ------ WiSUNError @@ -199,8 +204,11 @@ def _prepareClient(self): self.client.execSetRbId(self.config.config.b_route.id) cache = self.config.cache - if None in (cache.channel, cache.pan_id, cache.mac_addr): - self.logging.info("cache miss: scan results") + if force_scan or None in (cache.channel, cache.pan_id, cache.mac_addr): + if force_scan: + self.logging.info("force scan") + else: + self.logging.info("cache miss: scan results") self.vlcd.showProgress(11 / total_steps, "Scanning...") self.utime.sleep(self.SCAN_PRE_WAIT_SEC) retry_count = self.SCAN_RETRY @@ -245,7 +253,7 @@ def _prepareClient(self): retry_count -= 1 self.logging.info("BP35A1 join retry: " + str(retry_count)) continue - raise e + raise JoinError(str(e)) self.vlcd.showProgress(17 / total_steps, "Connected") self.logging.info("BP35A1 get meter status") @@ -332,7 +340,13 @@ def prepare(self): self.logging.info("<<< _prepareNtp()") self.logging.info(">>> _prepareClient()") - self._prepareClient() + try: + self._prepareClient() + except JoinError as e: + self.logging.exception(e) + # SKJOIN失敗時はSKSCAN強制実行ありで1回だけリトライする + self.logging.info("retry _prepareClient(True)") + self._prepareClient(True) self.logging.info("<<< _prepareClient()") self.logging.info(">>> _prepareTask()") @@ -827,4 +841,10 @@ class WiSUNError(Exception): """ pass +class JoinError(Exception): + """ + SKJOIN失敗時の例外 + """ + pass + # <<< meter diff --git a/wattmeter/wmconfig.py b/wattmeter/wmconfig.py index c766623..5cb273a 100644 --- a/wattmeter/wmconfig.py +++ b/wattmeter/wmconfig.py @@ -48,7 +48,7 @@ class WMConfig: }, "warning": None, "caution": None, - "update_interval": 15, + "update_interval": 30, "beep_volume": 3, "auto_reboot": True, "sync_cache": False,