Ejemplo n.º 1
0
def structure_init(server, ha_ip, pwd):

    api = remote.API(ha_ip, pwd)
    cfg = remote.get_config(api)
    # e.g. make version property

    print(cfg)

    uri = "http://hassopcua.lvonwedel.net"
    idx = server.register_namespace(uri)

    # create state type for HASS
    types = server.get_node(ua.ObjectIds.BaseObjectType)

    object_type_to_derive_from = server.get_root_node().get_child(
        ["0:Types", "0:ObjectTypes", "0:BaseObjectType"])
    ha_state_type = types.add_object_type(idx, "HAStateType")
    ha_state_type.add_variable(idx, "state", 1.0)

    # create objects
    objects = server.get_objects_node()

    loc_name = cfg['location_name']
    loc_node = objects.add_folder(idx, loc_name)
    loc_node.add_property(idx, "location_name", loc_name)
    loc_node.add_property(idx, "elevation", cfg['elevation'])
    loc_node.add_property(idx, "latitiude", cfg['latitude'])
    loc_node.add_property(idx, "longitude", cfg['longitude'])
    loc_node.add_property(idx, "version", cfg['version'])

    entities = remote.get_states(api)
    for entity in entities:
        # create the node
        node = loc_node.add_object(idx, entity.entity_id, ha_state_type.nodeid)

        # set the value for the state child variable
        state = node.get_child('%d:state' % idx)
        state.set_value(entity.state)

        # node.set_attribute(ua.AttributeIds.DisplayName, entity.attributes['friendly_name'])

        for attr in entity.attributes.keys():
            if attr in [
                    'latitude', 'longitude', 'unit_of_measurement',
                    'friendly_name'
            ]:
                node.add_property(idx, attr, entity.attributes[attr])

    return (idx, loc_name)
Ejemplo n.º 2
0
def cli(ctx, location, connect):
    """Get configuration details."""
    import homeassistant.remote as remote
    config = remote.get_config(ctx.api)

    if not location and not connect:
        ctx.log(json_output(config))
        ctx.vlog('Details of %s, Recieved: %s', ctx.host, timestamp())

    if location and not connect:
        url = '{0}/?mlat={2}&mlon={3}#map={1}/{2}/{3}'.format(
            OSM_URL, ZOOM, config.get('latitude'), config.get('longitude'))
        webbrowser.open_new_tab(url)

    if connect and not location:
        url = 'http://{}:{}'.format(ctx.host, DEFAULT_PORT)
        webbrowser.open_new_tab(url)
Ejemplo n.º 3
0
def cli(ctx):
    """Show the status of an instance."""
    import homeassistant.remote as remote
    config = remote.get_config(ctx.api)
    events = event_counter(ctx.api)

    ctx.log('Status of %s - %s - %s', ctx.host, config['location_name'],
            config['version'])

    status = []
    status.append(['Components', len(config['components'])])
    status.append(['Events', events.get('events')])
    status.append(['Listener count', events.get('total')])
    status.append(['Services', services_counter(ctx.api)])
    status.append(['Entities', entities_counter(ctx.api)])

    ctx.table(status)
    ctx.vlog('Details of %s, Created: %s', ctx.host, timestamp())
Ejemplo n.º 4
0
 def test_get_config(self):
     """Test the return of the configuration."""
     self.assertEqual(hass.config.as_dict(), remote.get_config(master_api))
Ejemplo n.º 5
0
 def get_config(self):
     pprint(remote.get_config(api))
 def test_get_config(self):
     """Test the return of the configuration."""
     self.assertEqual(hass.config.as_dict(), remote.get_config(master_api))
Ejemplo n.º 7
0
BCM2835_SPI_SPEED_4MHZ = 64

radio = RF24(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ)

address = [0x3130303030]  # "00001" (byte)
sensor_red = b'led_red'
sensor_green = b'led_green'
sensor_orange = b'led_orange'

# Read credentials from secrets.yaml
credentials = yaml.load(
    open('/home/homeassistant/.homeassistant/secrets.yaml'))
password = credentials['http_password']
api = remote.API('127.0.0.1', password)

print(remote.get_config(api))

print('Starting communication')
radio.begin()
radio.setPALevel(RF24_PA_LOW)
radio.setDataRate(RF24_250KBPS)
radio.setChannel(108)
radio.openReadingPipe(0, address[0])
radio.openWritingPipe(address[0])
radio.printDetails()

init = True

while True:

    if init:
Ejemplo n.º 8
0
 def _config(self):
     return remote.get_config(self.api)