samsinnamon / airtouch4pyapi

An api allowing control of AC state (temperature, on/off, mode) of an Airtouch 4 controller locally over TCP
MIT License
27 stars 14 forks source link

Could not send message to airtouch: [Errno 49] Can't assign requested address #26

Closed stanislavhordiyenko closed 8 months ago

stanislavhordiyenko commented 8 months ago

Hello, I am running a simple script:

import asyncio

from airtouch4pyapi import AirTouch, AirTouchStatus, AirTouchVersion

def print_groups(groups):
    for group in groups:
        print(f"Group Name: {group.GroupName:15s} Group Number: {group.GroupNumber:3d} PowerState: {group.PowerState:3s} IsOn: {group.IsOn} OpenPercent: {group.OpenPercent:3d} Temperature: {group.Temperature:3.1f} Target: {group.TargetSetpoint:3.1f} BelongToAc: {group.BelongsToAc:2d} Spill: {group.Spill}")

def print_acs(acs):
    for ac in acs:
        print(f"AC Name: {ac.AcName:15s} AC Number: {ac.AcNumber:3d} IsOn: {ac.IsOn} PowerState: {ac.PowerState:3s} Target: {ac.AcTargetSetpoint:3.1f} Temp: {ac.Temperature:3.1f} Modes Supported: {ac.ModeSupported} Fans Supported: {ac.FanSpeedSupported} startGroup: {ac.StartGroupNumber: 2d} GroupCount: {ac.GroupCount:2d} Spill: {ac.Spill}")

async def updateInfoAndDisplay():
    at = AirTouch("192.168.0.26", AirTouchVersion.AIRTOUCH5)
    await at.UpdateInfo()
    if(at.Status != AirTouchStatus.OK):
        print("Got an error updating info.  Exiting")
        return

if __name__ == '__main__':
    asyncio.run(updateInfoAndDisplay())

I am on Mac (M2, Ventura 13). I get this error:

AirTouchStatus.CONNECTION_LOST
Could not send message to airtouch: [Errno 49] Can't assign requested address
Got an error updating info.  Exiting

Could you please suggest how this can be fixed?

Thank you.

scottyai commented 8 months ago

Hi, I got a similar error and really have not dug into the real problem and is probably looks to be related to port setting. All I did was remove the version. This forces the code to run a "findVersion" and will update the version and port numbers for you as per below:

async def updateInfoAndDisplay(): at = AirTouch("192.168.0.26", AirTouchVersion.AIRTOUCH5) await at.UpdateInfo() if(at.Status != AirTouchStatus.OK): print("Got an error updating info. Exiting") return

stanislavhordiyenko commented 8 months ago

@scottyai yeah, you are right. It works without specifying the version. Much appreciated.