Skip to content

Commit

Permalink
items_by_type uses pycalaos types instead of Calaos types
Browse files Browse the repository at this point in the history
  • Loading branch information
tiramiseb committed May 19, 2023
1 parent 0f1ece2 commit cef3d97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ The client has the following methods and properties:
change since the previous poll
- `client.rooms`: rooms as a list of `pycalaos.client.Room`
- `client.items`: items as dictionary of item ID to `pycalaos.item.Item`
- `client.item_types`: list of item types present in this Calaos installation
- `client.items_by_type(type: str)`: returns all items of that type
- `client.item_gui_types`: list of item gui_types present in this Calaos
installation
- `client.items_by_gui_type(type: str)`: returns all items of that gui_type
- `client.item_types`: complete list of item types currently in use
- `client.items_by_type(type: type)`: returns all items of that type (see types
in the 2nd columns of the mapping table)

## Room

Expand Down Expand Up @@ -98,7 +96,7 @@ Events have the following properties:

Mapping from Calaos IOs to pycalaos items is based on the gui_type:

| Calaos type | pycalaos object |
| Calaos type | pycalaos object type |
| --------------- | ----------------------- |
| **Generic** |
| InPlageHoraire | io.InPlageHoraire |
Expand Down
26 changes: 4 additions & 22 deletions pycalaos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,20 @@ def reload_home(self):
rooms = []
items = {}
items_by_type = {}
items_by_gui_type = {}
for roomData in resp["home"]:
room = Room(roomData["name"], roomData["type"])
for itemData in roomData["items"]:
item = new_item(itemData, room, self._conn)
items[item._id] = item
try:
items_by_type[item.type].append(item)
items_by_type[type(item)].append(item)
except KeyError:
items_by_type[item.type] = [item]
try:
items_by_gui_type[item.gui_type].append(item)
except KeyError:
items_by_gui_type[item.gui_type] = [item]
items_by_type[type(item)] = [item]
room._addItem(item)
rooms.append(room)
self._rooms = rooms
self._items = items
self._items_by_type = items_by_type
self._items_by_gui_type = items_by_gui_type

def update_all(self):
"""Check all states and return events
Expand Down Expand Up @@ -195,24 +189,12 @@ def items(self):

@property
def item_types(self):
"""Complete list of item types present in this Calaos installation"""
"""Complete list of item types currently in use"""
return list(self._items_by_type.keys())

def items_by_type(self, type):
"""Return only the items with the given type"""
"""Return only the items of the given type"""
try:
return self._items_by_type[type]
except KeyError:
return []

@property
def item_gui_types(self):
"""Complete list of item gui types present in this Calaos installation"""
return list(self._items_by_gui_type.keys())

def items_by_gui_type(self, type):
"""Return only the items with the given gui type"""
try:
return self._items_by_gui_type[type]
except KeyError:
return []
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="pycalaos",
version="0.0.15",
version="0.0.16",
description="Calaos home automation client library",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit cef3d97

Please sign in to comment.