kvj / hass_openwrt

Home Assistant integration with OpenWrt devices
MIT License
114 stars 20 forks source link

WPS vs AP mode #1

Open ivomarino opened 3 years ago

ivomarino commented 3 years ago

Hi and thanks for this great integration, on my OpenWRT instance I don't have WPS so I hade to disable this part in the code:

        macs = dict()
        for key, value in response['clients'].items():
            macs[key] = dict(signal=value.get("signal"))
        #response = await self._ubus.api_call(
        #    f"hostapd.{interface_id}",
        #    'wps_status',    
        #    dict()
        #)                           
        return dict(
            clients=len(macs),
            macs=macs,  
            # wps=response["pbc_status"] == "Active"
        ) 

I just have normal AP clients cause running in AP mode, like:

ubus call hostapd.wlan1 get_clients
{
    "freq": 2462,
    "clients": {
        "xx:xx:xx:xx:xx:xx": {
            "auth": true,
            "assoc": true,
            "authorized": true,
            "preauth": false,
            "wds": false,
            "wmm": true,
            "ht": true,
            "vht": false,
            "wps": false,
            "mfp": false,
            "rrm": [
                0,
                0,
                0,
                0,
                0
            ],
            "aid": 2,
            "bytes": {
                "rx": 148449402,
                "tx": 8522063
            },
            "airtime": {
                "rx": 0,
                "tx": 0
            },
            "packets": {
                "rx": 153853,
                "tx": 99111
            },
            "rate": {
                "rx": 72200,
                "tx": 72200
            },
            "signal": -55,
            "capabilities": {

            }
        }
    }
}

would be great if we could add support also for this use case, thanks;)

ivomarino commented 3 years ago

I also had to modify this to exclude radio2:

    async def discover_wireless(self) -> dict:
        result = dict(ap=[], mesh=[])
        if not self.is_api_supported("network.wireless"):
            return result
        try:
            response = await self._ubus.api_call('network.wireless', 'status', {})
            for radio, item in response.items():
                if radio != 'radio2':                          <--------------------------  modified here
                    for iface in item['interfaces']:
                        conf = dict(ifname=iface['ifname'],network=iface['config']['network'][0])
                        if iface['config']['mode'] == 'ap':
                            result['ap'].append(conf)
                        if iface['config']['mode'] == 'mesh':
                            conf['mesh_id'] = iface['config']['mesh_id']
                            result['mesh'].append(conf)
        except NameError as err:
            _LOGGER.warning(
                f"Device [{self._id}] doesn't support wireless: {err}")
        return result

radio2 is a device which ist not active on a wrt3200acm, it's added to the config on boot. This interface needs to be skipped, if not we get a Python KeyError

kvj commented 2 years ago

Hi,

on my OpenWRT instance I don't have WPS so I hade to disable this part in the code

I've made WPS support optional. Please fetch the latest version and re-add your device. (there should be WPS support checkbox)

radio2 is a device which ist not active on a wrt3200acm, it's added to the config on boot

if you're not using it, why it's not disabled in the config then?

if not we get a Python KeyError

Where exactly did you get this error?