lawtancool / pyControl4

Python 3 asyncio package for interacting with Control4 systems
https://lawtancool.github.io/pyControl4
Apache License 2.0
38 stars 16 forks source link

API Error, not sure what is wrong #29

Closed parkers0405 closed 3 months ago

parkers0405 commented 3 months ago
2024-05-15 13:57:55,381 - app_logger - INFO - New thread created with ID: thread_7gWpUk7AmVM3EB5lsEgPPhX8
127.0.0.1 - - [15/May/2024 13:57:55] "GET /start HTTP/1.1" 200 -
2024-05-15 13:58:03,148 - app_logger - INFO - Received message: Turn the volume up in the living room to 15 for thread ID: thread_7gWpUk7AmVM3EB5lsEgPPhX8
2024-05-15 13:58:08,360 - app_logger - INFO - Processing tool call: set_volume with arguments: {'room_name': 'living room', 'volume': 15}
2024-05-15 13:58:08,361 - app_logger - INFO - Setting volume for room: living room, volume: 15
127.0.0.1 - - [15/May/2024 13:58:08] "POST /api/v1/items/16/commands HTTP/1.1" 404 -
2024-05-15 13:58:08,705 - app_logger - DEBUG - Raw response from /api/v1/items/16/commands: <!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

2024-05-15 13:58:08,707 - app_logger - ERROR - Error setting volume for room: living room, error: Invalid XML response from Control4 API: syntax error: line 1, column 0
Traceback (most recent call last):
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/error_handling.py", line 103, in checkResponseForError
    dictionary = xmltodict.parse(response_text)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/xmltodict.py", line 378, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/Main.py", line 229, in set_volume
    await room.setVolume(volume)
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/room.py", line 93, in setVolume
    await self.director.sendPostRequest(
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/director.py", line 101, in sendPostRequest
    await checkResponseForError(response_text)
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/error_handling.py", line 105, in checkResponseForError
    raise InvalidXMLResponse(f"Invalid XML response from Control4 API: {str(e)}")
pyControl4.error_handling.InvalidXMLResponse: Invalid XML response from Control4 API: syntax error: line 1, column 0
2024-05-15 13:58:08,712 - app_logger - INFO - Tool call output: {'error': 'Invalid XML response from Control4 API: syntax error: line 1, column 0'}
2024-05-15 13:58:14,728 - app_logger - INFO - Processing tool call: set_volume with arguments: {'room_name': 'living room', 'volume': 15}
2024-05-15 13:58:14,730 - app_logger - INFO - Setting volume for room: living room, volume: 15
127.0.0.1 - - [15/May/2024 13:58:14] "POST /api/v1/items/16/commands HTTP/1.1" 404 -
2024-05-15 13:58:14,998 - app_logger - DEBUG - Raw response from /api/v1/items/16/commands: <!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

2024-05-15 13:58:14,999 - app_logger - ERROR - Error setting volume for room: living room, error: Invalid XML response from Control4 API: syntax error: line 1, column 0
Traceback (most recent call last):
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/error_handling.py", line 103, in checkResponseForError
    dictionary = xmltodict.parse(response_text)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/xmltodict.py", line 378, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/Main.py", line 229, in set_volume
    await room.setVolume(volume)
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/room.py", line 93, in setVolume
    await self.director.sendPostRequest(
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/director.py", line 101, in sendPostRequest
    await checkResponseForError(response_text)
  File "/Users/parkersettle/Desktop/Chat Bots/Control4/Control4 GPT 3/control4/lib/python3.11/site-packages/pyControl4/error_handling.py", line 105, in checkResponseForError
    raise InvalidXMLResponse(f"Invalid XML response from Control4 API: {str(e)}")
pyControl4.error_handling.InvalidXMLResponse: Invalid XML response from Control4 API: syntax error: line 1, column 0
2024-05-15 13:58:15,002 - app_logger - INFO - Tool call output: {'error': 'Invalid XML response from Control4 API: syntax error: line 1, column 0'}
2024-05-15 13:58:19,936 - app_logger - INFO - Assistant response: I'm encountering persistent issues while attempting to adjust the volume in the living room. It seems there is an error with the system. I recommend checking the Control4 system for any network or configuration issues that might be causing this error. If the problem persists, conta
parkers0405 commented 3 months ago

This is the function I am using:

async def set_volume(room_name, volume, token):
    logger.info(f'Setting volume for room: {room_name}, volume: {volume}')
    room_id = skill_table["rooms"].get(room_name.lower())
    if room_id:
        director = C4Director(ip, token)
        room = C4Room(director, int(room_id))
        try:
            await room.setVolume(volume)
            logger.info(f"Volume set successfully for room {room_name}")
            return {"message": "Volume set successfully"}
        except Exception as e:
            logger.exception(f"Error setting volume for room: {room_name}, error: {str(e)}")
            return {"error": str(e)}
    else:
        logger.error(f"Invalid room name: {room_name}")
        return {"error": "Invalid room name"}