Skip to content

Commit 5a6c3a0

Browse files
committed
Replace tz lookup in current time
1 parent 945abfc commit 5a6c3a0

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

__init__.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,25 @@ def wrap_method(fn, arg_model=None):
127127

128128
def wrapper(message):
129129
start_time = time()
130-
if arg_model:
131-
result = fn(arg_model(*message.data['args'],
132-
**message.data['kwargs']))
133-
try:
134-
result = result.model_dump()
135-
except AttributeError:
136-
# Response is not a Pydantic model
137-
pass
138-
else:
139-
result = fn(*message.data['args'], **message.data['kwargs'])
130+
result = None
131+
error = None
132+
try:
133+
if arg_model:
134+
result = fn(arg_model(*message.data['args'],
135+
**message.data['kwargs']))
136+
try:
137+
result = result.model_dump()
138+
except AttributeError:
139+
# Response is not a Pydantic model
140+
pass
141+
else:
142+
result = fn(*message.data.get('args', []),
143+
**message.data.get('kwargs', {}))
144+
except Exception as e:
145+
error = str(e)
140146
message.context["skill_id"] = self.skill_id
141-
self.bus.emit(message.response(data={'result': result}))
147+
self.bus.emit(message.response(data={'result': result,
148+
'error': error}))
142149
LOG.info(f"API method completed in {time() - start_time}s")
143150
return wrapper
144151

@@ -232,10 +239,10 @@ def get_current_time(self, request: _CurrentTimeRequest) -> \
232239
:param request: Request containing location to get time of
233240
:returns: Response containing current timestamp
234241
"""
235-
#location = request.location or self.location['city']['name']
236-
#dt = self.get_local_datetime(location, None)
237-
#if not dt:
238-
# raise ValueError(f"Invalid location: {location}")
242+
location = request.location or self.location['city']['name']
243+
dt = self.get_local_datetime(location, None)
244+
if not dt:
245+
raise ValueError(f"Invalid location: {location}")
239246
return _CurrentTimeResponse(current_timestamp=time())
240247

241248
@skill_api_method

0 commit comments

Comments
 (0)