Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requestChannelState() #24

Open
Gozilla01 opened this issue Jul 30, 2019 · 0 comments
Open

requestChannelState() #24

Gozilla01 opened this issue Jul 30, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@Gozilla01
Copy link
Owner

Durante la creazione di un nuovo thing viene richiamato sia la funzione initialize() che requestChannelState() all'interno del handler specifico del thing.
Nel caso che si modifica dei parametri del thing esistente, sia in paperUI che nel file, viene richiamata solo initialize(). Non richiamando requestChannelState() non abbiamo una completa inizializzazione/stato dei canali e il thing rimane in OFFLINE.

Nel file OpenWebNetThingHandler nella funzione handleCommand(ChannelUID channel, Command command) viene richiamati i requestChannelState()
Questa parte del codice gestire il REFRESH nel thing.

if (command instanceof RefreshType) {
            logger.debug("==OWN:ThingHandler== Refreshing channel {}", channel);
            // TODO move to a refreshChannel() method that subclasses can implement to disable setting the thing offline
            requestChannelState(channel);
            // set a schedule to put device OFFLINE if no answer is received after THING_STATE_REQ_TIMEOUT
            scheduler.schedule(() -> {
                // if state is still unknown after timer ends, set the thing OFFLINE
                if (thing.getStatus().equals(ThingStatus.UNKNOWN)) {
                    logger.info(
                            "==OWN:ThingHandler== Thing state request timer expired, still unknown. Setting thing={} to OFFLINE",
                            thing.getUID());
                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                            "Could not get channel state");
                    logger.debug("==OWN:ThingHandler== Thing OFFLINE");
                }
            }, THING_STATE_REQ_TIMEOUT, TimeUnit.SECONDS);
            return;
        } else {
            handleChannelCommand(channel, command);
        }

Il command REFRESH avviene sono durante la creazione del thing e non dopo la modifica di uno o più parametri.
Altra nota all'interno del file

updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, "waiting state update...");
            // TODO handleCommand(REFRESH) : is it called automatically ? otherwise do here a:
            // bridgeHandler.requestDeviceState(getThing().getUID());

Mi domandavo se non era opportuno gestire il refresh del channel all'interno dei singoli handler nella funzione di initialize() aggiungendo questo codice:

updateStatus(ThingStatus.ONLINE);
ChannelUID channelUID;
for (Channel channel : getThing().getChannels()) {    
            logger.debug("==OWN:MotionDetectorHandler== initialize() request channel state thingUID={} channel={}",  thing.getUID(), channelUID.getId());      
            channelUID = channel.getUID();
            switch (channelUID.getId()) {
                case CHANNEL_MOTION_DETECTOR_SWITCH:
                    // is not possible to request channel state for Command buttons
                    updateState(channelUID, UnDefType.UNDEF);
                    break;
                case CHANNEL_MOTION_DETECTOR_VALUE:
                    bridgeHandler.gateway.send(LightingExt.requestMotionDetectorStatus(toWhere(channelUID),
                            lightingType, REQUEST_CHANNEL));
                    break;
                default: {
                    logger.warn("==OWN:MotionDetectorHandler== Unsupported ChannelUID {}", channelUID);
                }
            }
}

Penso, il problema dei CEN/CEN+ del cambio del nome sia associato a questo problema.
Una ricerca nei vari binding vedo, la gestione Request dei canali viene gestita all'interno di initialize()

Cosa facciamo ?

@Gozilla01 Gozilla01 added the bug Something isn't working label Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant