# Path: resources/lib/PhoneBooks/PhoneBookFacade.py
# class PhoneBookFacade(PhoneBookBase):
#     def __init__(self, imagepath):
#         PhoneBookBase.__init__(self, imagepath)
#         self._phoneBooks = []
#         for phone_book in _find_phone_book_classes():
#             self._phoneBooks.append(phone_book(imagepath))
# 
#     def set_settings(self, settings):
#         for phone_book in self._phoneBooks:
#             phone_book.set_settings(settings)
# 
#     def get_setting_keys(self):
#         merged_settings = {}
#         for phone_book in self._phoneBooks:
#             merged_settings.update(phone_book.get_setting_keys())
#         return merged_settings
# 
#     def imagecount(self):
#         count = 0
#         for phone_book in self._phoneBooks:
#             count += phone_book.imagecount()
#         return count
# 
#     def compareNumbers(self, a, b, ccode='0049'):
# 
#         a = str(re.sub('[^0-9\+\*]|((?<!\A)\+)', '', a))
#         b = str(re.sub('[^0-9\+\*]|((?<!\A)\+)', '', b))
# 
#         if a.startswith(ccode): a = '0' + a[len(ccode):]
#         if a.startswith('+'): a = '0' + a[3:]
# 
#         if b.startswith(ccode): b = '0' + b[len(ccode):]
#         if b.startswith('+'): b = '0' + b[3:]
# 
#         # a = a[-len(b):]
#         # b = b[-len(a):]
# 
#         return (a == b)
# 
#     def getPhonebook(self):
#         phone_books = {}
#         for phone_book in self._phoneBooks:
#             phone_books.update(phone_book.getPhonebook())
#         return phone_books


import socket
import os
import sys
import xbmc
import xbmcaddon
import xbmcgui
import re
import resources.lib.tools as tools
from resources.lib.PhoneBooks.PhoneBookFacade import PhoneBookFacade

        query = {
                "method": "Application.GetProperties",
                "params": {"properties": ["volume"]}
                }

        currVolume = tools.jsonrpc(query).get('volume', 0)
        _d = -2 if currVolume - int(volume) > 0 else 2
        steps = abs(currVolume - int(volume)) / 2
        if steps > 0 and fade:
            delay = 1200 / steps
            while steps > 0:
                currVolume += _d
                query = {
                        "method": "Application.SetVolume",
                        "params": {"volume": currVolume}
                        }
                res = tools.jsonrpc(query)
                steps -= 1
                xbmc.sleep(delay)
            return res
        else:
            query = {
                "method": "Application.SetVolume",
                "params": {"volume": int(volume)}
            }
        return tools.jsonrpc(query)


class FritzCallmonitor(object):

# Path: resources/lib/PhoneBooks/PhoneBookFacade.py
# class PhoneBookFacade(PhoneBookBase):
#     def __init__(self, imagepath):
#         PhoneBookBase.__init__(self, imagepath)
#         self._phoneBooks = []
#         for phone_book in _find_phone_book_classes():
#             self._phoneBooks.append(phone_book(imagepath))
# 
#     def set_settings(self, settings):
#         for phone_book in self._phoneBooks:
#             phone_book.set_settings(settings)
# 
#     def get_setting_keys(self):
#         merged_settings = {}
#         for phone_book in self._phoneBooks:
#             merged_settings.update(phone_book.get_setting_keys())
#         return merged_settings
# 
#     def imagecount(self):
#         count = 0
#         for phone_book in self._phoneBooks:
#             count += phone_book.imagecount()
#         return count
# 
#     def compareNumbers(self, a, b, ccode='0049'):
# 
#         a = str(re.sub('[^0-9\+\*]|((?<!\A)\+)', '', a))
#         b = str(re.sub('[^0-9\+\*]|((?<!\A)\+)', '', b))
# 
#         if a.startswith(ccode): a = '0' + a[len(ccode):]
#         if a.startswith('+'): a = '0' + a[3:]
# 
#         if b.startswith(ccode): b = '0' + b[len(ccode):]
#         if b.startswith('+'): b = '0' + b[3:]
# 
#         # a = a[-len(b):]
#         # b = b[-len(a):]
# 
#         return (a == b)
# 
#     def getPhonebook(self):
#         phone_books = {}
#         for phone_book in self._phoneBooks:
#             phone_books.update(phone_book.getPhonebook())
#         return phone_books


# Path: default.py
import socket
import os
import sys
import xbmc
import xbmcaddon
import xbmcgui
import re
import resources.lib.tools as tools
from resources.lib.PhoneBooks.PhoneBookFacade import PhoneBookFacade


        query = {
                "method": "Application.GetProperties",
                "params": {"properties": ["volume"]}
                }

        currVolume = tools.jsonrpc(query).get('volume', 0)
        _d = -2 if currVolume - int(volume) > 0 else 2
        steps = abs(currVolume - int(volume)) / 2
        if steps > 0 and fade:
            delay = 1200 / steps
            while steps > 0:
                currVolume += _d
                query = {
                        "method": "Application.SetVolume",
                        "params": {"volume": currVolume}
                        }
                res = tools.jsonrpc(query)
                steps -= 1
                xbmc.sleep(delay)
            return res
        else:
            query = {
                "method": "Application.SetVolume",
                "params": {"volume": int(volume)}
            }
        return tools.jsonrpc(query)


class FritzCallmonitor(object):

    __phoneBookFacade = None