-
Notifications
You must be signed in to change notification settings - Fork 10
Wifi Entity for Windows #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Yes I agree with setting the full path in the command |
|
We need to find a way to define a different unit for different OS in Hass: % if Windows, dBm otherwise. |
| if OsD.IsWindows(): | ||
| self.keySignalStrength = KEY_SIGNAL_STRENGTH_PERCENT | ||
| self.valueFormatterOptionsSignalStrength = VALUEFORMATTEROPTIONS_PERCENTAGE | ||
| else: | ||
| self.keySignalStrength = KEY_SIGNAL_STRENGTH_DBM | ||
| self.valueFormatterOptionsSignalStrength = VALUEFORMATTEROPTIONS_DBM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richibrics
Shouldnt this already do the trick?
I'll add the conversion from percent to dbm
Maybe we let the user configure if he wants percent or dbm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
infeeeee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to find some language agnostic solution for this, this is not maintainable.
Check how this old python module works: https://github.com/awkman/pywifi
| } | ||
| self.patterns = { | ||
| OsD.WINDOWS: { | ||
| "en": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is the only way to get this data? Windows 11 has support for 110 languages, are you sure you want to write this for all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent never was to support all languages. I'll look at other ways.
| KEY_SIGNAL_STRENGTH_PERCENT = "signal_strength_percent" | ||
| KEY_SIGNAL_STRENGTH_DBM = "signal_strength_dbm" | ||
|
|
||
| # WINDOWS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need so much KEYS? I think the most important 5-10 would be enough (state, ssid, ip and mac address, signal level, etc.)
Take a look at the HomeAssistant mobile app, there are only 10 wifi related sensors there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reduced them to be less than 10 for each OS.
Though i just deleted some that i valued the less.
|
@infeeeee suggested to have a look at https://github.com/awkman/pywifi. They take a better approach on getting wifi information. They utilize the ctypes module and directly communicate with windows apis. |
I was also thinking about this, but that module seems not really maintained, last commit was 5 years ago, the maintainer hasn't done anything on Github since 2019. And it has a lot of features we don't need (e.g. it can connect to network). So using this as a dependency would be a bit risky and overkill. We already use ctypes in other entities. The license of pywifi is more lax, so you can copy paste code from there. On linux I played a bit with it. We should use |
|
as i was fiddling around wit pywifi i came to the same conclusion. Pywifi itself is built upon https://github.com/6e726d/PyWiWi (same boilerplate for ctypes etc.). I'll try to get a minimum working example going. The change to iw looks pretty straightforward, having no locales to worry about is also a +. |
|
I got a necessary minimum copied from PyWifi. def status(self, obj):
"""Get the wifi interface status."""
data_size = DWORD()
data = PDWORD()
opcode_value_type = DWORD()
self._wlan_query_interface(self._handle, obj['guid'], 6,
byref(data_size), byref(data),
byref(opcode_value_type))
return status_dict[data.contents.value]# Define interface status.
IFACE_DISCONNECTED = 0
IFACE_SCANNING = 1
IFACE_INACTIVE = 2
IFACE_CONNECTING = 3
IFACE_CONNECTED = 4Querying for its rssi is giving me a headache though, my very basic c knowledge is keeping me back understanding this approach and microsofts docs. Keeping close to PyWifis usage above def rssi(self, obj):
"""Get the wifi interface status."""
data_size = PDWORD()
data = LONG()
opcode_value_type = DWORD()
self._wlan_query_interface(self._handle, obj['guid'], 23,
byref(data_size), byref(data),
byref(opcode_value_type))
return data.contents.valuechanging the opcode from 6 to 23 This presents the following output in data.contents: I pushed my test script if anyone wants to take a look. |
|
I'll have to drop windows support if it has to be done by calling windows apis directly. That stuff just flies right over my head. @richibrics shall I refactor Linux and mac support into another pr? This way the beginning of the windows implementation will just remain her for someone to pickup on. |
|
Yes sounds great, I will make it working on Windows in the future |




I saw the network entity lingering in ToImplement and while wokring on that did the wifi entity first, since this was the original functionality of the network entity.
Options for configuration:
EntityState
ExtraAttributes
Multiple Instances:
Configuration:
Windows:

Linux:

Edgecases:

If some Information is not available it is not shown: (behaviour is the same on all OS)