Skip to content

Commit

Permalink
Disconnect on websocket error
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmarks committed Sep 15, 2020
1 parent a282470 commit da00ef8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gekitchen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""GE Kitchen Appliances SDK"""

__version__ = "0.2.14"
__version__ = "0.2.15"


from .async_login_flow import (
Expand Down
7 changes: 5 additions & 2 deletions gekitchen/clients/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ async def async_run_client(self, appliances: Optional[List[GeAppliance]] = None,
await self.subscribe_appliances(appliances)
await self.get_appliance_list()
await self.async_event(EVENT_CONNECTED, None)
async for message in socket:
await self.process_message(message)
try:
async for message in socket:
await self.process_message(message)
except websockets.WebSocketException:
_LOGGER.error("Unknown error reading socket")
_LOGGER.info("Disconnected")
if self._keepalive_fut is not None:
self._keepalive_fut.cancel()
Expand Down
16 changes: 9 additions & 7 deletions gekitchen/ge_appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class GeAppliance:
def __new__(cls, mac_addr: Union[str, JID], client: "GeBaseClient", *args, **kwargs):
if isinstance(mac_addr, JID):
mac_addr = str(mac_addr.user).split('_')[0]
obj = cls._appliance_cache.get(mac_addr) # type: Optional["GeAppliance"]
if obj is not None:
if client.client_priority > obj.client.client_priority:
obj.client = client
try:
obj = cls._appliance_cache[mac_addr] # type: "GeAppliance"
except KeyError:
obj = super(GeAppliance, cls).__new__(cls, mac_addr, client, *args, **kwargs)
obj.__init__(mac_addr, client)
cls._appliance_cache[obj.mac_addr] = obj
return obj
obj = super(GeAppliance, cls).__new__(cls)
obj.__init__(mac_addr, client)
cls._appliance_cache[obj.mac_addr] = obj
else:
if client.client_priority >= obj.client.client_priority:
obj.client = client
return obj

def __init__(self, mac_addr: Union[str, JID], client: "GeBaseClient"):
Expand Down

0 comments on commit da00ef8

Please sign in to comment.