Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cdce8p
Copy link
Contributor

@cdce8p cdce8p commented May 13, 2018

Note: This PR is based on #118 to avoid merge conflicts. I will rebase it as soon as the other one is merged. Until then the last commit contains the changes for this PR.

Description

This is a follow up to #105. Currently (semi-)static information are distributed across multiple classes which makes it more difficult to track which are used and when. Eg. the private and public key are generated for every accessory even if it's bridged.

Changes

  • Added Config helper class
  • Moved vars from accessory_driver and accessory to it, inclusive the pairing methods
  • Added pincode parameter to accessory_driver, since it has been deprecated for accessories
  • Added / converted methods to deprecated
  • Updated encoder and AccessoryMDNSServiceInfo
  • In theory this PR does not include any breaking changes, only if deprecated methods are called on before the driver is set for an accessory

@codecov-io
Copy link

codecov-io commented May 13, 2018

Codecov Report

Merging #120 into dev will increase coverage by 0.21%.
The diff coverage is 65.33%.

@@            Coverage Diff             @@
##              dev     #120      +/-   ##
==========================================
+ Coverage   50.82%   51.04%   +0.21%     
==========================================
  Files          14       15       +1     
  Lines        1332     1340       +8     
  Branches      140      140              
==========================================
+ Hits          677      684       +7     
  Misses        642      642              
- Partials       13       14       +1
Impacted Files Coverage Δ
pyhap/hap_server.py 26.08% <0%> (ø) ⬆️
pyhap/accessory.py 47.12% <0%> (-4.83%) ⬇️
pyhap/state.py 100% <100%> (ø)
pyhap/encoder.py 100% <100%> (ø) ⬆️
pyhap/const.py 100% <100%> (ø) ⬆️
pyhap/accessory_driver.py 56.27% <75%> (ø) ⬆️
pyhap/util.py 72.72% <0%> (+2.27%) ⬆️

@cdce8p
Copy link
Contributor Author

cdce8p commented May 13, 2018

@ikalchev What do you think about marking these methods as deprecated in contrast to removing them directly? I figured that you want to limit breaking changes, which is why I didn't remove them.

Would be open to deleting them directly as well.

Copy link
Owner

@ikalchev ikalchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comments

if self.mac or self._pincode:
self.driver.config.set_values(mac=self.mac, pincode=self._pincode)

def add_paired_client(self, client_uuid, client_public):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safe to remove add/remove_paired, I don't think it will break someone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them and acc.config_version, acc.pincode and acc.paired as well, since they are all mainly used locally.

pyhap/config.py Outdated
self.private_key = sk
self.public_key = vk

@property
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really any value in making this a @Property instead of initialising it in the init? For me this just adds overhead

Copy link
Contributor Author

@cdce8p cdce8p May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all properties and moved that to init as suggested. Removed set_values as well.

pyhap/config.py Outdated
self._setup_id = util.generate_setup_id()
return self._setup_id

def set_values(self, *, address=None, config_version=None, mac=None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Can't we make all fields "public" by removing the underscore and the @ property - after all, this is a data class

pyhap/config.py Outdated
logger = logging.getLogger(__name__)


class Config:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: What do you think about State instead (config implies something that does not change at runtime)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State is better. I've changed it.

cdce8p added 3 commits May 16, 2018 12:28
* Renamed 'config.py' to 'state.py'
* Ranamed 'Config' class to 'State'
* Made properties public and removed 'set_values'
* Added module to documentation
@ikalchev
Copy link
Owner

What do you think about caching driver.state in the Accessory? Technically, it is the state of the Accessory, which is managed by the driver, so maybe it makes sense and will also save some odd x.y.z.foo.bar syntax.

Anyway, I won't be holding back the merge because of the above, we can do it at a later point if we decide.

@ikalchev ikalchev merged commit e92529a into ikalchev:dev May 17, 2018
@cdce8p cdce8p deleted the impr-7-config branch May 17, 2018 20:02
@cdce8p
Copy link
Contributor Author

cdce8p commented May 17, 2018

I don't think that's really necessary. We would just increase the referrence count unnecessarily and decrease readability. The most of the driver.state refferences are in the deprecated methods anyway.

ikalchev added a commit that referenced this pull request May 18, 2018
* Merge master back into dev (#111)

* Fix typo in log message (#112)

* Fix typo in SDS011

* Documentation improvements for version 2.0.0 (#114)

* Replace event_loop with loop (#107)

* Changelog update (#116)

* Added entry for event loop change

* Additional changes

* Small changes - Accessory (#117)

* Improved bridge.to_HAP

* Updated changelog

* Fix another typo in SDS011 which prevented pm10 from getting updates.

* Added getter_callback to Characteristic #78

* Fix typo bridge.to_HAP (#119)

* Adding Code Style Checker (#118)

* Add basis for style checker

* Fixed lint errors

* Updated changelog

* Improvements 7 - Config class (#120)

Added a State class which keeps Accessory runtime properties such as port, address, paired clients, etc. This state is stored and managed by the driver.

* Remove the pyhap.accessories package. (#115)

* Remove the pyhap.accessories package.

All accessories are temporarily moved to the root accessories folder.
These will be moved into separate repositories as appropriate.

pyhap.accessories is now an implicit namespace package. See
pyhap/accessories/README.md for how others can share their accessories
as HAP-python subpackages.

* Release v2.1.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants