예제 #1
0
파일: room.py 프로젝트: krzysztofz1/gateway
 def dto_to_orm(room_dto):  # type: (RoomDTO) -> Room
     room = Room.get_or_none(number=room_dto.id)
     if room is None:
         room = Room(number=room_dto.id)
     if 'name' in room_dto.loaded_fields:
         room.name = room_dto.name
     return room
예제 #2
0
파일: rooms.py 프로젝트: rolaya/gateway
 def _get_or_create_room(eext_controller,
                         room_id,
                         rooms,
                         floors,
                         skip_empty=False):
     # type: (EepromExtension, int, Dict[int, Room], Dict[int, Floor], bool) -> Optional[Room]
     if room_id not in rooms:
         room = Room.get_or_none(number=room_id)
         if room is None:
             room_data = RoomsMigrator._read_eext_fields(
                 eext_controller, 'RoomConfiguration', room_id,
                 ['floor', 'name'])
             name = room_data.get('name', '')
             try:
                 floor_id = int(room_data.get('floor', 255))
             except ValueError:
                 floor_id = 255
             if skip_empty and name == '' and floor_id == 255:
                 return None
             room = Room(number=room_id, name=name)
             if floor_id != 255:
                 room.floor = RoomsMigrator._get_or_create_floor(
                     eext_controller, floor_id, floors)
             room.save()
             RoomsMigrator._delete_eext_fields(eext_controller,
                                               'RoomConfiguration', room_id,
                                               ['floor', 'name'])
         rooms[room_id] = room
     return rooms[room_id]
예제 #3
0
파일: room.py 프로젝트: rolaya/gateway
 def dto_to_orm(room_dto, fields):  # type: (RoomDTO, List[str]) -> Room
     room = Room.get_or_none(number=room_dto.id)
     if room is None:
         room = Room(number=room_dto.id)
     if 'name' in fields:
         room.name = room_dto.name
     return room