mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.38k stars 479 forks source link

Feature Request: Expose discovery values in Device class? #697

Closed Jibun-no-Kage closed 2 years ago

Jibun-no-Kage commented 2 years ago

Feature Request: Expose discovery values in Device class? The only way to retrieve discovered information is via a canned format? repr or str?

You can pull firmware version, temperature, humidity, but you can't pull name, type, IP, port, or MAC address? Device class could be changed to allow for more information to be pulled explicitly.

Jibun-no-Kage commented 2 years ago

Not familiar with pull request process or merging changes, but since it was easy to do I just added the following code to my instance to test the idea...

` def get_host(self): """Return host of the device.""" host,port=self.host return (host)

def get_port(self):
    """Return port of the device."""
    host,port=self.host
    return (port)

def get_mac(self):
    """Return MAC address of the device."""
    mac=":".join(format(x, "02X") for x in self.mac)
    return (mac)

def get_devtype(self):
    """Return type of the device."""
    return (hex(self.devtype))

def get_timeout(self):
    """Return time out of the device."""
    return (self.timeout)

def get_name(self):
    """Return name of the device."""
    return (self.name)

def get_model(self):
    """Return model of the device."""
    return (self.model)

def get_manufacturer(self):
    """Return manufacturer of the device."""
    return (self.manufacturer)

def get_is_locked(self):
    """Return lock state of the device."""
    return (self.is_locked)

`

For example...

` # broadlink.setup(SSID, PASSPHARSE, SECURITY)

    #
    DEVICES=broadlink.discover(discover_ip_address=BROADCAST)
    theDevices=[]

    for theDevice in DEVICES:

            theAuthorization=theDevice.auth()
            theSensors=theDevice.check_sensors()

            #
            theSensors['device']=str(theDevice)
            theSensors['firmware']=theDevice.get_fwversion()
            theSensors['type']=theDevice.get_type()

            theSensors['host']=theDevice.get_host()
            theSensors['port']=theDevice.get_port()
            theSensors['mac']=theDevice.get_mac()
            theSensors['devtype']=theDevice.get_devtype()
            theSensors['timeout']=theDevice.get_timeout()
            theSensors['name']=theDevice.get_name()
            theSensors['model']=theDevice.get_model()
            theSensors['manufacturer']=theDevice.get_manufacturer()
            theSensors['is_locked']=theDevice.get_is_locked()

            #
            theDevices.append(theSensors)

    #
    print(repr(theDevices))

`

Sample output from code example above...

[{'temperature': 35.01, 'humidity': 29.31, 'device': '智能遥控 (Broadlink RM4 mini 0x648d / 192.168.1.1:80 / XX:XX:XX:XX:XX:XX)', 'firmware': 52079, 'type': 'RM4MINI', 'host': '192.168.1.1', 'port': 80, 'mac': 'XX:XX:XX:XX:XX:XX', 'devtype': '0x648d', 'timeout': 10, 'name': '智能遥控', 'model': 'RM4 mini', 'manufacturer': 'Broadlink', 'is_locked': False}]

I hope you will consider adding the above to the solution.

felipediel commented 2 years ago

These methods are not necessary, we can query the properties directly. Instead of theDevice.get_manufacturer() we use theDevice.manufacturer, for example.

Jibun-no-Kage commented 2 years ago

Ah... that works, thanks.