Closed chemelli74 closed 2 years ago
The method should not return
False
in case the service is not available, because this would be an ambiguous result.
True, I started from the point of view of my "needs" for such method and not a generic one.
Also the method returns
None
in case that there is no "NewEnable" entry in the dictionary provided bycall_action()
: in a boolean contextNone
would interpreted asFalse
masking the real error.
Indeed, same as above.
Can we have also a "upnp_capable
" method then ? ;-)
@property
def upnp_capable(self):
"""
Returns a boolean whether upnp is available on the device.
"""
return "X_AVM-DE_UPnP1" in self.fc.services
Instead it should be implemented like:
@property def upnp_enabled(self): """ Returns a boolean whether upnp is enabled or raises a FritzServiceError in case the service is not available. """ status = self.fc.call_action("X_AVM-DE_UPnP1", "GetInfo") return status["NewEnable"]
The first line will raise a
FritzServiceError
if the API is not provided and the second line aKeyError
in case of a corrupted dictionary. Both errors are unlikely, however this is a clean separation and the return value is just about the upnp-setting.
Will update code.
Simone
Can we have also a "upnp_capable" method then ? ;-)
Well, makes no real sense because this could be a generic one-liner on application level ;)
def has_service(fc, service_name):
return service_name in fc.services
Library methods should not be trivial ones but make things easier which are harder otherwise. And if it is just because not to remember a service-name with the according action. A lot of properties in the library are about this. But in general a method should make it in the library if some non-application-specific pre- or post-processing is required for a call_action()
call.
Add a method to know if the device has UPnP configured or not.
cc @mib1185