Skip to content

Commit

Permalink
Merge pull request #7 from gaojiafamily/dev
Browse files Browse the repository at this point in the history
Fix Websocket EEW issue
  • Loading branch information
J1A-T13N authored Aug 22, 2024
2 parents 6a44ba0 + a7cfe71 commit 610e14e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion custom_components/trem/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
MIN_HA_MAJ_VER = 2024
MIN_HA_MIN_VER = 3
__min_ha_version__ = f"{MIN_HA_MAJ_VER}.{MIN_HA_MIN_VER}.0"
__version__ = "1.3.5"
__version__ = "1.3.6"

# Earthquake Icon
EARTHQUAKE_ICON = {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/trem/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"codeowners": ["@J1A-T13N", "@watermelon1024"],
"domain": "trem",
"name": "Taiwan Real-time Earthquake Monitoring",
"version": "1.3.5",
"version": "1.3.6",
"config_flow": true,
"documentation": "https://github.com/gaojiafamily/ha-trem/blob/master/README.md",
"issue_tracker": "https://github.com/gaojiafamily/ha-trem/issues",
Expand Down
16 changes: 7 additions & 9 deletions custom_components/trem/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,23 @@ def __init__(
def update(self):
"""Schedule a custom update via the common entity update service."""

data: dict = {}
if isinstance(self._coordinator.earthquakeData, dict):
data = self._coordinator.earthquakeData
eew: EEW | None = None
data = self._coordinator.earthquakeData

if len(data) > 0:
if isinstance(data, list) and len(data) > 0:
self.simulator = None

eew = EEW.from_dict(data[0])
elif isinstance(self.simulator, dict):
data = self.simulator
if self.simulatorTime is None:
self.simulatorTime = datetime.now()

eew = EEW.from_dict(self.simulator)

time = datetime.now() - self.simulatorTime
if time.total_seconds() >= 240:
self.simulator = None

eew: EEW | None = None
if "id" in data:
eew = EEW.from_dict(data)

if isinstance(eew, EEW):
earthquakeSerial = f"{eew.id} (Serial {eew.serial})"
if self._eew is None:
Expand Down
5 changes: 4 additions & 1 deletion custom_components/trem/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ async def _recv(self):

if eventType == WebSocketEvent.EEW.value:
if data.get("author", None) == "cwa":
self.earthquakeData = data
msgTime = msg_data.get("time", 0)
tmpData: dict = data
tmpData["time"] = data.get("time", msgTime)
self.earthquakeData = [tmpData]

if eventType == WebSocketEvent.TSUNAMI.value:
if data.get("author", None) == "cwa":
Expand Down

0 comments on commit 610e14e

Please sign in to comment.