Ejemplo n.º 1
0
 def test_save_load_from_json(self):
     device = self.create_device()
     jdata = device.save_to_json()
     restored_device = SonyDevice.load_from_json(jdata)
     jdata_restored = restored_device.save_to_json()
     self.assertEqual(jdata, jdata_restored)
     self.assertEqual(restored_device.client_id, device.client_id)
Ejemplo n.º 2
0
def load_device():
    """Restore the device from disk."""
    import os
    sony_device = None
    if os.path.exists(CONFIG_FILE):
        with open(CONFIG_FILE, 'r') as content_file:
            json_data = content_file.read()
            sony_device = SonyDevice.load_from_json(json_data)
    return sony_device
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Sony Media Player platform."""
    host = config.get(CONF_HOST)

    if host is None:
        return

    pin = None
    sony_config = load_json(hass.config.path(SONY_CONFIG_FILE))

    while sony_config:
        # Set up a configured TV
        host_ip, host_config = sony_config.popitem()
        if host_ip == host:
            device = SonyDevice.load_from_json(host_config)
            hass_device = SonyMediaPlayerEntity(device)
            add_devices([hass_device])
            return

    setup_sonymediaplayer(config, pin, hass, add_devices)
Ejemplo n.º 4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Sony Media Player platform."""
    host = config.get(CONF_HOST)

    if host is None:
        return

    pin = None
    sony_config = load_json(hass.config.path(SONY_CONFIG_FILE))
    from sonyapilib.device import SonyDevice

    while sony_config:
        # Set up a configured TV
        host_ip, host_config = sony_config.popitem()
        if host_ip == host:
            device = SonyDevice.load_from_json(host_config['device'])
            hass_device = SonyMediaPlayerDevice(host, device.nickname,
                                                device.pin, device.mac)
            hass_device.sonydevice = device
            add_devices([hass_device])
            return

    setup_sonymediaplayer(config, pin, hass, add_devices)
Ejemplo n.º 5
0
    def load_device(self):
        '''
        Restore the device from disk.
        Config file will be created during the registration process.
        '''

        import os
        sony_device = None

        self.logging.info("SONY load: " + self.device_ip + ", " +
                          self.device_name + ", " + self.device_config)

        try:
            if os.path.exists(self.device_config):
                with open(self.device_config, 'r') as content_file:
                    json_data = content_file.read()
                sony_device = SonyDevice.load_from_json(json_data)
            else:
                self.logging.error("SONY load device: file not found (" +
                                   self.device_config + ")")
            return sony_device

        except Exception as e:
            self.logging.error("SONY load device: " + str(e))
Ejemplo n.º 6
0
import json
from sonyapilib.device import SonyDevice

config_file = 'bluray.json'

with open(config_file, 'r') as myfile:
    data = myfile.read()

device = SonyDevice.load_from_json(data)

hass_cfg = {}
hass_cfg[device.host] = {}
hass_cfg[device.host]["device"] = data
print(json.dumps(hass_cfg), file=open("sony.conf", "w"))