Skip to content

Commit

Permalink
Bugfix set name (#24)
Browse files Browse the repository at this point in the history
* Update name

* Bugfix, could not set name

* remove todo
  • Loading branch information
Ekman authored Oct 17, 2021
1 parent e4d7a12 commit 844cef4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/purei9/purei9.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,22 @@ def battery_to_hass(pure_i9_battery: str) -> int:
"""Translate Pure i9 data into a Home Assistant battery level"""
return PURE_I9_BATTERY_MAP.get(pure_i9_battery, 0)

# Should not be specifically disabling properties.
# Rewrite this class as a TypedDict instead.
# pylint: disable=too-few-public-methods
class Params:
"""Data available in the state"""
name: str
battery: int = 100
state: str = STATE_IDLE
available: bool = True
firmware: str = None

def __init__(self, unique_id: str, name: str):
self._unique_id = unique_id
self._name = name
self.name = name

@property
def unique_id(self) -> str:
"""Immutable unique identifier"""
return self._unique_id

@property
def name(self) -> str:
"""Immutable name"""
return self._name
5 changes: 5 additions & 0 deletions tests/test_purei9.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ def test_params(self):
self.assertEqual(name, params.name)
self.assertEqual(100, params.battery)

# Attempt to set a new name
new_name = "hello,world"
params.name = new_name
self.assertEqual(new_name, params.name)

if __name__ == '__main__':
unittest.main()

0 comments on commit 844cef4

Please sign in to comment.