Skip to content

Commit

Permalink
Merge pull request #1 from zuku/handle-session-termination
Browse files Browse the repository at this point in the history
セッションが切断された後にエラーループに陥る問題の修正
  • Loading branch information
zuku committed May 19, 2023
2 parents 532b716 + aa24267 commit 71406a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/assets/config_full.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"watt": 2000,
"beep": true
},
"update_interval": 30,
"update_interval": 15,
"beep_volume": 5,
"auto_reboot": false,
"sync_cache": true
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wmconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 25 additions & 5 deletions wattmeter/meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()")
Expand Down Expand Up @@ -827,4 +841,10 @@ class WiSUNError(Exception):
"""
pass

class JoinError(Exception):
"""
SKJOIN失敗時の例外
"""
pass

# <<< meter
2 changes: 1 addition & 1 deletion wattmeter/wmconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 71406a7

Please sign in to comment.