Skip to content

Commit 223e3a3

Browse files
committed
Add Try and Exception
1 parent 47ae9f9 commit 223e3a3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

climate.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
# SUPPORT_SWING_MODE
4848
)
4949

50+
def tryApiStatus(func):
51+
def wrapper_call(*args, **kwargs):
52+
try:
53+
func(*args, **kwargs)
54+
except:
55+
args[0]._api.login()
56+
func(*args, **kwargs)
57+
return wrapper_call
58+
5059
def setup_platform(hass, config, add_entities, discovery_info=None):
5160
"""Set up the panasonic cloud components."""
5261
_LOGGER.debug('The panasonic_smart_app is setting up Platform.')
@@ -86,6 +95,7 @@ def __init__(self, device, api):
8695
# self._eco = 'Auto'
8796
# self._preset_mode = 'off'
8897

98+
@tryApiStatus
8999
def update(self):
90100
_LOGGER.debug('-----------UPDATING-----------')
91101
"""Update the state of this climate device."""
@@ -134,6 +144,7 @@ def hvac_modes(self):
134144
modes_list.append(self._api.taiSEIA.COMMANDS_OPTIONS.get('0x01').get(str(mode[1])))
135145
return modes_list
136146

147+
@tryApiStatus
137148
def set_hvac_mode(self, hvac_mode):
138149
_LOGGER.debug(f"{self._name} set_hvac_mode: {hvac_mode}")
139150
if hvac_mode == HVAC_MODE_OFF:
@@ -212,6 +223,7 @@ def current_temperature(self):
212223
"""Return the current temperature."""
213224
return self._current_temperature
214225

226+
@tryApiStatus
215227
def set_temperature(self, **kwargs):
216228
"""Set new target temperature."""
217229
target_temp = kwargs.get(ATTR_TEMPERATURE)

smartApp/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def login(self):
2020
'AppToken': self.app_token
2121
}
2222
response = requests.post(urls.login(), json = data)
23-
response.raise_for_status()
24-
print(response.json().get('CPToken'))
23+
# response.raise_for_status()
24+
# print(response.json().get('CPToken'))
2525
self.CPToken = response.json().get('CPToken')
2626
self.header = {
2727
'Content-Type': 'application/json',
@@ -46,6 +46,7 @@ def getDeviceInfo(self, deviceId=None, options=['0x00', '0x01', '0x03', '0x04'])
4646
commands['CommandTypes'].append({ "CommandType": option })
4747

4848
response = requests.post(urls.getDeviceInfo(), headers = self.header, json = [commands])
49+
response.raise_for_status()
4950
result = {}
5051
if (response.status_code == 200):
5152
for device in response.json().get('devices', []):
@@ -65,5 +66,6 @@ def setCommand(self, deviceId=None, command=0, value=0):
6566
"Value": value
6667
}
6768
response = requests.get(urls.setCommand(), headers = self.header, params = payload)
68-
pprint(vars(response))
69+
response.raise_for_status()
70+
# pprint(vars(response))
6971
return True

0 commit comments

Comments
 (0)