Exemplo n.º 1
0
def sony_get_power( ):
    """Query projector power status"""
    res=[]
    for k in config.prj_ip.keys():
        ip = config.prj_ip[k]
        p = pysdcp.Projector(ip)
        res = res + [{"ip" : ip , "power" : p.get_power()} ]
    return(res)
Exemplo n.º 2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Connect to Sony projector using network."""

    host = config[CONF_HOST]
    name = config[CONF_NAME]
    sdcp_connection = pysdcp.Projector(host)

    # Sanity check the connection
    try:
        sdcp_connection.get_power()
    except ConnectionError:
        _LOGGER.error("Failed to connect to projector '%s'", host)
        return False
    _LOGGER.debug("Validated projector '%s' OK", host)
    add_entities([SonyProjector(sdcp_connection, name)], True)
    return True
Exemplo n.º 3
0
def sony_set_power(on_off : bool):
    """Turn the Sony projectors on"""
    res=[]
    for k in config.prj_ip.keys():
        ip = config.prj_ip[k]
        try:
            p = pysdcp.Projector(ip)
            p.set_power(on_off)
            r =  p.get_power()
        except Exception as e:
            result = ["Failed:" + e.strerror]
            status = "exception"
            r = "unknown"

        res = res + [{"ip" : ip , "power" : r} ]

    return(res)
Exemplo n.º 4
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Connect to Sony projector using network."""

    host = config[CONF_HOST]
    name = config[CONF_NAME]
    sdcp_connection = pysdcp.Projector(host)

    # Sanity check the connection
    try:
        sdcp_connection.get_power()
    except ConnectionError:
        _LOGGER.error("Failed to connect to projector '%s'", host)
        return
    _LOGGER.debug("Validated projector '%s' OK", host)
    add_entities([SonyProjector(sdcp_connection, name)], True)
Exemplo n.º 5
0
import paho.mqtt.client as mqtt
import pysdcp
import time

lastState = ""
projector = pysdcp.Projector('beamer.rzl')


def on_connect(client, userdata, flags, rc):
    print("connected")
    client.subscribe("/service/beamer/command")


def on_message(client, userdata, msg):
    payload = msg.payload
    print(payload)
    global lastState
    lastState = ""
    if (payload == b'ON' or payload == b'1'):
        projector.set_power(True)
    elif (payload == b'OFF' or payload == b'0'):
        projector.set_power(False)
    else:
        client.publish("/service/beamer/error",
                       payload="unknown command. please pass 0, 1, ON or OFF",
                       qos=0)


client = mqtt.Client()
client.will_set('/service/beamer/state', 'offline', 0, True)
client.on_connect = on_connect